//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hustcad.plm.pdm.partbom.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.Lists;
import com.hustcad.plm.basic.util.TyCommonExtUtil;
import com.hustcad.plm.basic.util.TyplmEntityBaseUtil;
import com.hustcad.plm.basic.util.TyplmLoggerUtil;
import com.hustcad.plm.caddocapi.service.TyplmCADInitialCheckinDataService;
import com.hustcad.plm.configuredbom.dto.QueryFeatureCommonConditionDTO;
import com.hustcad.plm.configuredbom.service.product.TyplmConfiguredVariantSpecService;
import com.hustcad.plm.configuredbom.vo.VariantSpecVariantLinkVO;
import com.hustcad.plm.configuredbom.vo.product.TyplmConfiguredVariantSpecVO;
import com.hustcad.plm.pdm.access.service.PdmAccessJudgeService;
import com.hustcad.plm.pdm.classification.service.TyplmClassificationService;
import com.hustcad.plm.pdm.common.component.CompletableFutureWrapper;
import com.hustcad.plm.pdm.common.util.CommonUtil;
import com.hustcad.plm.pdm.common.util.PartBomUtils;
import com.hustcad.plm.pdm.common.util.TyplmPermissionsUtil;
import com.hustcad.plm.pdm.container.service.TyplmContainerService;
import com.hustcad.plm.pdm.doc.vo.DocDetails;
import com.hustcad.plm.pdm.enumeration.service.TyplmEnumerationItemService;
import com.hustcad.plm.pdm.enumeration.service.TyplmEnumerationService;
import com.hustcad.plm.pdm.enumeration.service.TyplmLocalePropertyValueService;
import com.hustcad.plm.pdm.extension.service.iteration.TyplmCompanyVersionService;
import com.hustcad.plm.pdm.file.util.FileConvertUtils;
import com.hustcad.plm.pdm.filevault.model.vo.ContentDataFileVO;
import com.hustcad.plm.pdm.filevault.model.vo.FileDataVO;
import com.hustcad.plm.pdm.filevault.service.TyplmContentDataService;
import com.hustcad.plm.pdm.folder.model.dto.MoveObjectParamsDTO;
import com.hustcad.plm.pdm.folder.service.TyplmFolderService;
import com.hustcad.plm.pdm.folder.service.TyplmIterFolderMemberLinkService;
import com.hustcad.plm.pdm.folder.service.TyplmProductFolderService;
import com.hustcad.plm.pdm.folder.service.TyplmSubFolderLinkService;
import com.hustcad.plm.pdm.iba.model.dto.IBAQueryDTO;
import com.hustcad.plm.pdm.iba.model.vo.AttributeDefVO;
import com.hustcad.plm.pdm.iba.model.vo.IbaAttrsVO;
import com.hustcad.plm.pdm.iba.service.TyplmAttributeService;
import com.hustcad.plm.pdm.iba.service.TyplmAttributeValueService;
import com.hustcad.plm.pdm.iba.service.TyplmIBAValueService;
import com.hustcad.plm.pdm.iba.service.TyplmStatusValueService;
import com.hustcad.plm.pdm.iteration.service.TyplmBranchidControlService;
import com.hustcad.plm.pdm.iteration.service.TyplmIteratorUtilService;
import com.hustcad.plm.pdm.lifestage.model.dto.NewLifeCycleStateHistoryDTO;
import com.hustcad.plm.pdm.lifestage.service.TyplmCommonLifecycleService;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifeCycleHistoryService;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifecycleTemplateService;
import com.hustcad.plm.pdm.partbom.dto.*;
import com.hustcad.plm.pdm.partbom.dto.bom.BomCondition;
import com.hustcad.plm.pdm.partbom.enums.PartBomErrorCodeEnum;
import com.hustcad.plm.pdm.partbom.mapper.TyplmPartMapper;
import com.hustcad.plm.pdm.partbom.mapper.TyplmPartMasterMapper;
import com.hustcad.plm.pdm.partbom.mapper.TyplmPartQueryExtendMapper;
import com.hustcad.plm.pdm.partbom.mapper.TyplmPartQueryMapper;
import com.hustcad.plm.pdm.partbom.query.PagePartQuery;
import com.hustcad.plm.pdm.partbom.query.PartAllQuery;
import com.hustcad.plm.pdm.partbom.query.TyQueryMultiObjectOIDByContion;
import com.hustcad.plm.pdm.partbom.service.*;
import com.hustcad.plm.pdm.partbom.service.extdatatable.TyplmExtDataValueQueryService;
import com.hustcad.plm.pdm.partbom.service.search.TyplmPartSearchService;
import com.hustcad.plm.pdm.partbom.service.view.TyplmViewDefService;
import com.hustcad.plm.pdm.partbom.vo.PageInfoVO;
import com.hustcad.plm.pdm.partbom.vo.*;
import com.hustcad.plm.pdm.partbom.vo.asyn.PartinfoVO;
import com.hustcad.plm.pdm.series.model.dto.TySeriesOutDTO;
import com.hustcad.plm.pdm.series.servcie.TyplmSeriesService;
import com.hustcad.plm.pdm.type.model.vo.TypeVueVO;
import com.hustcad.plm.pdm.type.service.TyplmTypeCommonService;
import com.hustcad.plm.pdm.type.service.TyplmTypeExtService;
import com.hustcad.plm.pdm.type.service.TyplmTypeService;
import com.hustcad.plm.pdm.user.model.vo.ContainerVO;
import com.hustcad.plm.pdm.user.service.TyplmOrgContainerService;
import com.hustcad.plm.pdm.user.service.TyplmUserService;
import com.jsyxdl.primary.service.PartTypeDefService;
import com.ty.basic.common.ITyLifecycleHelper;
import com.ty.basic.config.TySwitchConfig;
import com.ty.basic.constant.CommonConstant;
import com.ty.basic.constant.PartConstant;
import com.ty.basic.datasource.TyDynamicDataSource;
import com.ty.basic.dto.AccessJudgeDTO;
import com.ty.basic.dto.ParamIdDTO;
import com.ty.basic.dto.PartLinkDocDTO;
import com.ty.basic.dto.ReferenceBaseDTO;
import com.ty.basic.entity.CTyEntityBaseDO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.PrincipalEntity;
import com.ty.basic.entity.TyBaseObject;
import com.ty.basic.entity.cad.CADInitialCheckinDataDO;
import com.ty.basic.entity.doc.DocDO;
import com.ty.basic.entity.folder.CabinetDO;
import com.ty.basic.entity.folder.SubfolderDO;
import com.ty.basic.entity.iteration.ControlBranchDO;
import com.ty.basic.entity.lifecycle.LifeCycleTemplateDO;
import com.ty.basic.entity.org.OrgContainerDO;
import com.ty.basic.entity.org.UserDO;
import com.ty.basic.entity.part.PartDO;
import com.ty.basic.entity.part.PartMasterDO;
import com.ty.basic.entity.type.TypeDO;
import com.ty.basic.entity.view.ViewDefDO;
import com.ty.basic.enums.StatusActionEnum;
import com.ty.basic.handler.exceptionhandler.exception.ResponseCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.TyException;
import com.ty.basic.query.MyCreateObjQuery;
import com.ty.basic.query.PartQuery;
import com.ty.basic.service.snow.SnowflakeIdComponent;
import com.ty.basic.session.TyAccountContext;
import com.ty.basic.util.*;
import com.ty.basic.utils.BatchQueryHelper;
import com.ty.basic.utils.ConvertUtils;
import com.ty.basic.vo.*;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cglib.core.Converter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class TyplmPartServiceImpl implements TyplmPartService, ITyLifecycleHelper {
    private static final Logger log = LoggerFactory.getLogger(TyplmPartServiceImpl.class);
    private static final ImmutableBiMap<Object, Object> MAP = ImmutableBiMap.builder().put("number", "pm.partnumber").put("id", "p.oid").put("name", "pm.name").put("version", "p.version").put("iteration", "p.iterationid ::NUMERIC").put("createtime", "p.createstamp").put("modifytime", "p.modifystamp").put("productid", "p.resourcecategroyid").put("templateid", "p.typeid").put("erporgcode", "p.orgCode").put("source", "p.sourcekey").put("view", "v.name").put("lifecyclestate", "p.lifecyclestagekey").build();
    private static final String PARAM_ASSEMBLYMODE = "AssemblyMode";
    @Resource
    private TyplmPartMapper typlmPartMapper;
    @Resource
    private TyplmPartQueryMapper typlmPartQueryMapper;
    @Resource
    private TyplmPartQueryExtendMapper typlmPartQueryExtendMapper;
    @Resource
    private TyplmPartMasterMapper typlmPartMasterMapper;
    @Resource
    private TyplmViewDefService typlmViewDefService;
    @Resource
    private TyplmUserService typlmUserService;
    @Resource
    private TyplmSubFolderLinkService typlmSubFolderLinkService;
    @Resource
    private TyplmBranchidControlService typlmBranchidControlService;
    @Resource
    private TyplmOrgContainerService typlmOrgContainerService;
    @Resource
    private TyplmTypeService typlmTypeService;
    @Resource
    private TyplmPermissionsUtil typlmPermissionsUtil;
    @Resource
    private TyplmStatusValueService typlmStatusValueService;
    @Resource
    private TyplmContainerService typlmContainerService;
    @Resource
    private SnowflakeIdComponent snowflakeIdComponent;
    @Resource
    private TyplmEnumerationService typlmEnumerationService;
    @Resource
    private TyplmFolderService typlmFolderService;
    @Resource
    private TyplmLifeCycleHistoryService typlmLifeCycleHistoryService;
    @Resource
    private TyplmIterFolderMemberLinkService typlmIterFolderMemberLinkService;
    @Autowired
    private TyplmCommonLifecycleService typlmCommonLifecycleService;
    @Resource
    private TyplmIteratorUtilService typlmIteratorUtilService;
    @Resource
    private TyplmPartIteratorService typlmPartIteratorService;
    @Resource
    private TyplmPartEarlyService typlmPartEarlyService;
    @Resource
    private TyplmAttributeValueService typlmAttributeValueService;
    @Resource
    private TyplmIBAValueService typlmIBAValueService;
    @Autowired
    private TySwitchConfig tySwitchConfig;
    @Autowired
    private TyplmLocalePropertyValueService typlmLocalePropertyValueService;
    @Resource
    private TyplmLifecycleTemplateService typlmLifecycleTemplateService;
    @Resource
    private TyplmSeriesService typlmSeriesService;
    @Resource
    private TyplmPartSearchService typlmPartSearchService;
    @Resource
    private TyplmExtDataValueQueryService typlmExtDataValueQueryService;
    @Resource
    private TyplmEnumerationItemService typlmEnumerationItemService;
    @Resource
    private TyplmCADInitialCheckinDataService typlmCADInitialCheckinDataService;
    @Resource
    private TyplmProductFolderService typlmProductFolderService;
    @Resource
    private TyplmPartRelObjectService typlmPartRelObjectService;
    @Resource
    private TyplmContentDataService typlmContentDataService;
    @Resource
    private TyplmPartService typlmPartService;
    @Resource
    private TyplmClassificationService typlmClassificationService;
    @Resource
    private TyplmAttributeService typlmAttributeService;
    @Resource
    private PartBomUtils partBomUtils;
    @Resource
    private PdmAccessJudgeService pdmAccessJudgeService;
    @Resource
    private TyplmCompanyVersionService typlmCompanyVersionService;
    @Resource
    private TyplmConfiguredVariantSpecService typlmConfiguredVariantSpecService;
    @Resource
    private TyplmConfiguredSuperBomService typlmConfiguredSuperBomService;
    @Resource
    private TyplmTypeExtService typlmTypeExtService;
    @Resource
    private TyplmTypeCommonService typlmTypeCommonService;
    @Resource
    CompletableFutureWrapper completableFutureWrapper;
    @Value("${es.search.switch:false}")
    private boolean esSearchSwitch;
    private static final int PG_IN_DEFAUTL_COUNT_FOR_PART = 300;
    private static final int SEARCH_RESULT_COUNT_MAX_COUNT = 20000;

    public TyplmPartServiceImpl() {
    }

    public PartDetailsVO getLatestPartVersionDetail(BomCondition bomCondition) {
        return this.queryPartDetails(this.typlmPartService.getLatestPartVersion(bomCondition), "");
    }

    public List<PartDO> queryLastedByPartIdList(List<BigInteger> partIdList) {
        return CollUtil.isEmpty(partIdList) ? Collections.emptyList() : BatchQueryHelper.batchSplitQuery(partIdList, (collection) -> {
            return this.typlmPartMapper.queryLastedByPartIdList((List)collection);
        });
    }

    public List<PartDO> queryLastedByPartMasterListAndView(List<BigInteger> partMasterIdList, List<BigInteger> viewListId) {
        return CollUtil.isEmpty(partMasterIdList) ? Collections.emptyList() : BatchQueryHelper.batchSplitQuery(partMasterIdList, (collection) -> {
            return this.typlmPartMapper.queryLastedByPartMasterList((List)collection, viewListId, CommonUtil.getUserOid());
        });
    }

    public List<PartDO> queryPartByDescribeCad(List<BigInteger> cadIdList, BigInteger userId) {
        return BatchQueryHelper.batchSplitQuery(cadIdList, (collection) -> {
            return this.typlmPartMapper.queryPartByDescribeCad((List)collection, userId);
        });
    }

    public List<PartVO> queryPartVoByDescribeCad(List<BigInteger> cadIdList, BigInteger userId) {
        return BatchQueryHelper.batchSplitQuery(cadIdList, (collection) -> {
            return this.typlmPartMapper.queryPartVOByDescribeCad((List)collection, userId);
        });
    }

    public List<TyPartAllVO> queryPartByCondition(PartQuery partQuery) {
        PagePartQuery pagePartQuery = new PagePartQuery();
        pagePartQuery.setIsExactQuery(partQuery.getNumberExactString());
        if (StringUtil.isNotEmpty(partQuery.getLockerOid())) {
            pagePartQuery.setUserOid(partQuery.getLockerOid());
        }

        if (StringUtils.isNotEmpty(partQuery.getMdaLocation())) {
            pagePartQuery.setMdaLocation(partQuery.getMdaLocation());
        }

        this.setQueryNumber(partQuery, pagePartQuery);
        this.setQueryName(partQuery, pagePartQuery);
        this.setQueryEnDescription(partQuery, pagePartQuery);
        pagePartQuery.setCreator(partQuery.getCreatorOid());
        if (StringUtils.isNotEmpty(partQuery.getPartViewName())) {
            pagePartQuery.setView(partQuery.getPartViewName());
        }

        pagePartQuery.setIsMajorVersion(partQuery.getIsMajorVersion());
        if (StringUtil.isNotEmpty(partQuery.getOrderBy())) {
            pagePartQuery.setOrderBy(partQuery.getOrderBy().toLowerCase(Locale.ROOT));
        }

        if (StringUtil.isNotEmpty(partQuery.getSort())) {
            pagePartQuery.setSort(partQuery.getSort().toLowerCase(Locale.ROOT));
        }

        this.setQueryPage(partQuery, pagePartQuery);
        List<TyPartAllVO> tyPartAllVOS = this.getTyPartAllVOS(partQuery, pagePartQuery);
        this.checkPartPermission(partQuery, tyPartAllVOS);
        return tyPartAllVOS;
    }

    private List<TyPartAllVO> getTyPartAllVOS(PartQuery partQuery, PagePartQuery pagePartQuery) {
        List res;
        if (!"Latest".equalsIgnoreCase(partQuery.getVersion()) && !StringUtils.isEmpty(partQuery.getVersion())) {
            this.setQueryVersion(partQuery, pagePartQuery);
            res = this.getAllPartsSupplyAsync(partQuery, pagePartQuery);
        } else {
            pagePartQuery.setIsLatest(1);
            res = this.getLatestPartsSupplyAsync(partQuery, pagePartQuery);
        }

        return res;
    }

    private List<TyPartAllVO> getLatestPartsSupplyAsync(PartQuery partQuery, PagePartQuery pagePartQuery) {
        List res;
        if (!partQuery.getIsQueryCount()) {
            if ("YES".equals(partQuery.getIsQueryNoView())) {
                res = this.typlmPartMapper.queryPartLatestNoView(pagePartQuery);
            } else {
                res = this.typlmPartMapper.queryPartLatestByCondition(pagePartQuery);
            }
        } else {
            String currentDS = TyAccountContext.getDataSource();
            CompletableFuture<Integer> asyncQueryPartCount = this.completableFutureWrapper.supplyAsync(() -> {
                TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

                Integer var3;
                try {
                    var3 = this.getCount(this.typlmPartMapper.queryLatestPartCountByCondition(pagePartQuery));
                } finally {
                    TyDynamicDataSource.clearCurDataSource();
                }

                return var3;
            });
            CompletableFuture<List<TyPartAllVO>> asyncQueryPart = this.completableFutureWrapper.supplyAsync(() -> {
                return this.getLatestTyPartAllVOS(partQuery, pagePartQuery, currentDS);
            });
            Integer count = (Integer)asyncQueryPartCount.join();
            partQuery.setTotal((long)count);
            this.throwCountException(asyncQueryPart, count);
            boolean cancel = false;
            if (count == 0) {
                cancel = asyncQueryPart.cancel(true);
            }

            res = this.getResByAsyncCancel(cancel, asyncQueryPart);
        }

        this.setPartLatestSymbols(res);
        return res;
    }

    private List<TyPartAllVO> getLatestTyPartAllVOS(PartQuery partQuery, PagePartQuery pagePartQuery, String currentDS) {
        TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

        List var4;
        try {
            if ("YES".equals(partQuery.getIsQueryNoView())) {
                var4 = this.typlmPartMapper.queryPartLatestNoView(pagePartQuery);
                return var4;
            }

            var4 = this.typlmPartMapper.queryPartLatestByCondition(pagePartQuery);
        } finally {
            TyDynamicDataSource.clearCurDataSource();
        }

        return var4;
    }

    private void setPartLatestSymbols(List<TyPartAllVO> res) {
        Iterator var2 = res.iterator();

        while(var2.hasNext()) {
            TyPartAllVO tyPartAllVO = (TyPartAllVO)var2.next();
            tyPartAllVO.setIsLatest("Y");
            tyPartAllVO.setLatestPartVersionID(StringUtil.trim(tyPartAllVO.getOid()));
        }

    }

    private List<TyPartAllVO> getResByAsyncCancel(boolean cancel, CompletableFuture<List<TyPartAllVO>> asyncQueryPart) {
        return cancel ? Collections.emptyList() : (List)asyncQueryPart.join();
    }

    private List<TyPartAllVO> getAllPartsSupplyAsync(PartQuery partQuery, PagePartQuery pagePartQuery) {
        List res;
        if (!partQuery.getIsQueryCount()) {
            if ("YES".equals(partQuery.getIsQueryNoView())) {
                res = this.typlmPartMapper.queryPartByConditionNoView(pagePartQuery);
            } else {
                res = this.typlmPartMapper.queryPartByCondition(pagePartQuery);
            }
        } else {
            String currentDS = TyAccountContext.getDataSource();
            CompletableFuture<Integer> asyncQueryPartCount = this.completableFutureWrapper.supplyAsync(() -> {
                TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

                Integer var3;
                try {
                    var3 = this.getCount(this.typlmPartMapper.queryPartCountByCondition(pagePartQuery));
                } finally {
                    TyDynamicDataSource.clearCurDataSource();
                }

                return var3;
            });
            CompletableFuture<List<TyPartAllVO>> asyncQueryPart = this.completableFutureWrapper.supplyAsync(() -> {
                return this.getTyPartByCondition(partQuery, pagePartQuery, currentDS);
            });
            Integer count = (Integer)asyncQueryPartCount.join();
            partQuery.setTotal((long)count);
            this.throwCountException(asyncQueryPart, count);
            boolean cancel = false;
            if (count == 0) {
                cancel = asyncQueryPart.cancel(true);
            }

            res = this.getResByAsyncCancel(cancel, asyncQueryPart);
        }

        if (!partQuery.getIsUpdateParts()) {
            this.batchGetLatestPartVersions(res, pagePartQuery);
        }

        return res;
    }

    private List<TyPartAllVO> getTyPartByCondition(PartQuery partQuery, PagePartQuery pagePartQuery, String currentDS) {
        TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

        List var4;
        try {
            if ("YES".equals(partQuery.getIsQueryNoView())) {
                var4 = this.typlmPartMapper.queryPartByConditionNoView(pagePartQuery);
                return var4;
            }

            var4 = this.typlmPartMapper.queryPartByCondition(pagePartQuery);
        } finally {
            TyDynamicDataSource.clearCurDataSource();
        }

        return var4;
    }

    private Integer getCount(int i) {
        int count = i;
        if (i > 20000) {
            count = -1;
        }

        return count;
    }

    private void throwCountException(CompletableFuture<List<TyPartAllVO>> asyncQueryPart, Integer count) {
        if (count < 0) {
            asyncQueryPart.cancel(true);
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_SEARCH_RESULT_EXCEED_THE_UPPER_LIMIT, new String[]{"20000"});
        }

    }

    private void batchGetLatestPartVersions(List<TyPartAllVO> res, PagePartQuery pagePartQuery) {
        if (!CollectionUtils.isEmpty(res)) {
            List<BigInteger> partIds = (List)res.stream().map(PartDO::getOid).collect(Collectors.toList());
            List<LatestPartVersionVO> latestPartVersionVOs = BatchQueryHelper.batchSplitQuery(partIds, (collection) -> {
                return this.typlmPartMapper.batchGetLatestPartVersionID((List)collection, pagePartQuery.getUserOid());
            });
            Map<String, List<LatestPartVersionVO>> mapLatestPartVersionInfo = (Map)latestPartVersionVOs.stream().collect(Collectors.groupingBy(LatestPartVersionVO::getPartVersionID));
            Iterator var6 = res.iterator();

            while(var6.hasNext()) {
                TyPartAllVO part = (TyPartAllVO)var6.next();
                boolean flag = part.getVersion().concat(".").concat(part.getIterationid()).equalsIgnoreCase(((LatestPartVersionVO)((List)mapLatestPartVersionInfo.get(part.getOid().toString())).get(0)).getVersion());
                part.setLatestPartVersionID(String.valueOf(((LatestPartVersionVO)((List)mapLatestPartVersionInfo.get(part.getOid().toString())).get(0)).getLatestPartVersionID()));
                if (flag) {
                    part.setIsLatest("Y");
                }
            }
        }

    }

    private void setQueryVersion(PartQuery partQuery, PagePartQuery pagePartQuery) {
        if ("ALL".equalsIgnoreCase(partQuery.getVersion()) && "YES".equalsIgnoreCase(pagePartQuery.getIsMajorVersion())) {
            pagePartQuery.setIsLatest(1);
        } else if (partQuery.getVersion().contains(".")) {
            String[] versionArray = partQuery.getVersion().split("\\.");
            if (versionArray.length == 2) {
                String majorVersion = versionArray[0];
                String minorVersion = versionArray[1];
                pagePartQuery.setMajorVersion(majorVersion);
                pagePartQuery.setMinorVersion(minorVersion);
            }
        } else if (!"ALL".equalsIgnoreCase(partQuery.getVersion())) {
            pagePartQuery.setIsLatest(1);
            pagePartQuery.setMajorVersion(partQuery.getVersion());
        }

    }

    private void checkPartPermission(PartQuery partQuery, List<TyPartAllVO> res) {
        if (!CollectionUtils.isEmpty(res) && partQuery.getIsCheckRight()) {
            if (!"ALL".equalsIgnoreCase(partQuery.getVersion())) {
                boolean permissionflag = this.typlmPermissionsUtil.checkPermissions((TyBaseObject)res.get(0), "读取", partQuery.getLockerOid());
                if (!permissionflag) {
                    TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_RIGHT_NO_READ, new String[]{CommonUtil.getEntityDisplayName((CTyEntityBaseDO)res.get(0))});
                }
            }

            UserDO userDO = this.typlmUserService.queryUserByKey(partQuery.getLockerOid());
            List<TyBaseObject> tyBaseObjectList = new ArrayList();
            List<String> listPermissionName = new ArrayList();
            res.stream().forEach((tyBaseObject) -> {
                tyBaseObjectList.add(tyBaseObject);
                listPermissionName.add("读取");
            });
            List<String> noPermissionOids = this.typlmPermissionsUtil.getNoPermissionOids(userDO, tyBaseObjectList, listPermissionName);
            if (!CollectionUtils.isEmpty(noPermissionOids)) {
                res.removeIf((tyPartAllVO) -> {
                    return noPermissionOids.contains(tyPartAllVO.getOid().toString());
                });
            }
        }

    }

    private void setQueryPage(PartQuery partQuery, PagePartQuery pagePartQuery) {
        if ((long)partQuery.getPageNum() > PartConstant.LONG_ZERO && (long)partQuery.getPageSize() > PartConstant.LONG_ZERO) {
            int currentPage = partQuery.getPageNum();
            int pageSize = partQuery.getPageSize();
            int pageStart = (currentPage - 1) * pageSize;
            int pageEnd = pageStart + pageSize;
            pagePartQuery.setPageStart(pageStart);
            pagePartQuery.setPageEnd(pageEnd);
            pagePartQuery.setSize(pageSize);
        }

    }

    private void setQueryName(PartQuery partQuery, PagePartQuery pagePartQuery) {
        if ("NO".equalsIgnoreCase(pagePartQuery.getIsExactQuery())) {
            if (StringUtils.isNotBlank(partQuery.getName())) {
                String name = this.replaceSpecialCharacter(partQuery.getName());
                pagePartQuery.setName(name);
            }
        } else {
            pagePartQuery.setName(partQuery.getName());
        }

    }

    private void setQueryEnDescription(PartQuery partQuery, PagePartQuery pagePartQuery) {
        if (StringUtils.isNotBlank(partQuery.getEnglishDes())) {
            String englishDes = this.replaceSpecialCharacter(partQuery.getEnglishDes());
            pagePartQuery.setEnDescription(englishDes);
        }

    }

    private void setQueryNumber(PartQuery partQuery, PagePartQuery pagePartQuery) {
        if (!StringUtils.isEmpty(partQuery.getPartNumber())) {
            if (partQuery.getPartNumber().contains(",")) {
                String[] batchNumberArray = partQuery.getPartNumber().split(",");
                List<String> batchNumberList = new ArrayList(Arrays.asList(batchNumberArray));
                pagePartQuery.setBatchNumber(batchNumberList);
                pagePartQuery.setBatchNumStr(partQuery.getPartNumber());
                pagePartQuery.setPartNumber((String)null);
            } else if ("NO".equalsIgnoreCase(pagePartQuery.getIsExactQuery())) {
                if (partQuery.getPartNumber().length() < 4) {
                    TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_LESS_THAN_LENGTH, new String[]{"PartNumber", "4"});
                }

                String partNumber = this.replaceSpecialCharacter(partQuery.getPartNumber());
                pagePartQuery.setPartNumber(partNumber);
            } else {
                pagePartQuery.setPartNumber(partQuery.getPartNumber());
            }

        }
    }

    private String replaceSpecialCharacter(String stringB) {
        String stringA = stringB.replace("/", "//");
        stringA = stringA.replace("%", "/%");
        stringA = stringA.replace("_", "/_");
        stringA = stringA.replace("}", "/}");
        stringA = stringA.replace("{", "/{");
        stringA = stringA.replace("}", "/}");
        stringA = stringA.replace("[", "/[");
        stringA = stringA.replace("]", "/]");
        stringA = stringA.replace("!", "/!");
        stringA = stringA.replace("@", "/@");
        stringA = stringA.replace("#", "/#");
        stringA = stringA.replace("&", "/&");
        stringA = stringA.replace("*", "/*");
        stringA = stringA.replace("(", "/(");
        stringA = stringA.replace(")", "/)");
        stringA = stringA.replace("-", "/-");
        stringA = stringA.replace("=", "/=");
        stringA = stringA.replace("+", "/+");
        return stringA;
    }

    public PageInfo<TyPartAllVO> queryPagePartByCondition(PartQuery partQuery) {
        PagePartQuery pagePartQuery = new PagePartQuery();
        if (StringUtils.isEmpty(partQuery.getNumberExactString())) {
            pagePartQuery.setIsExactQuery("NO");
        } else {
            pagePartQuery.setIsExactQuery(partQuery.getNumberExactString());
        }

        if (StringUtil.isNotEmpty(partQuery.getLockerOid())) {
            pagePartQuery.setUserOid(partQuery.getLockerOid());
        }

        this.setQueryNumber(partQuery, pagePartQuery);
        this.setQueryName(partQuery, pagePartQuery);
        this.setQueryEnDescription(partQuery, pagePartQuery);
        pagePartQuery.setCreator(partQuery.getCreatorOid());
        pagePartQuery.setView(partQuery.getPartViewName());
        pagePartQuery.setIsMajorVersion(partQuery.getIsMajorVersion());
        if (!"Latest".equals(partQuery.getVersion()) && !StringUtils.isEmpty(partQuery.getVersion())) {
            return this.getTyPartAllVOPageInfo(partQuery, pagePartQuery);
        } else {
            pagePartQuery.setIsLatest(1);
            PageMethod.startPage(partQuery.getPageNum(), partQuery.getPageSize());
            List<TyPartAllVO> res = this.typlmPartMapper.queryPartLatestByCondition(pagePartQuery);
            return new PageInfo(res);
        }
    }

    private PageInfo<TyPartAllVO> getTyPartAllVOPageInfo(PartQuery partQuery, PagePartQuery pagePartQuery) {
        this.setQueryVersion(partQuery, pagePartQuery);
        PageMethod.startPage(partQuery.getPageNum(), partQuery.getPageSize());
        List<TyPartAllVO> res = this.typlmPartMapper.queryPartByCondition(pagePartQuery);
        return new PageInfo(res);
    }

    public PartDO queryPartByOid(BigInteger oid, String otype) {
        return (PartDO)this.typlmPartMapper.selectByPrimaryKey(oid);
    }

    public TyPartAllVO queryPartAllByOid(BigInteger oid, String otype, BigInteger useroid, boolean isCheckRight) {
        if (Objects.equals(otype, "")) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"otype"});
        }

        if (useroid.compareTo(BigInteger.ZERO) == 0) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{String.valueOf(useroid)});
        }

        if (isCheckRight) {
            PartDO partDO = (PartDO)this.typlmPartMapper.selectByPrimaryKey(oid);
            if (partDO != null) {
                boolean flag = this.typlmPermissionsUtil.checkPermissions(partDO, "读取", useroid);
                if (!flag) {
                    TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_RIGHT_NO_READ, new String[]{CommonUtil.getEntityDisplayName(partDO)});
                }
            }
        }

        TyPartAllVO partAllVO = new TyPartAllVO();
        PagePartQuery pagePartQuery = new PagePartQuery();
        pagePartQuery.setOid(oid);
        List<TyPartAllVO> partAllVOS = this.typlmPartMapper.queryPartByCondition(pagePartQuery);
        if (!CollectionUtils.isEmpty(partAllVOS)) {
            partAllVO = (TyPartAllVO)partAllVOS.get(0);
            BomCondition bomCondition = new BomCondition();
            bomCondition.setMasteredoid(partAllVO.getMasteredoid());
            bomCondition.setViewdefoid(partAllVO.getViewdefoid());
            bomCondition.setVariation1(partAllVO.getVariation1());
            bomCondition.setVariation2(partAllVO.getVariation2());
            LatestPartVersionVO latestPartVersionVO = this.typlmPartMapper.getLatestPartVersionID(bomCondition, useroid);
            if (Objects.isNull(latestPartVersionVO)) {
                latestPartVersionVO = this.typlmPartMapper.queryLatestPartVersionID(partAllVO.getMasteredoid(), useroid, partAllVO.getViewdefoid());
            }

            this.queryLatestVO(partAllVO, latestPartVersionVO);
        }

        return partAllVO;
    }

    private void queryLatestVO(TyPartAllVO partAllVO, LatestPartVersionVO latestPartVersionVO) {
        if (!ObjectUtils.isEmpty(latestPartVersionVO)) {
            partAllVO.setLatestPartVersionID(StringUtil.trim(latestPartVersionVO.getLatestPartVersionID()));
            String inputVersion = partAllVO.getVersion().concat(".").concat(partAllVO.getIterationid());
            if (inputVersion.equals(latestPartVersionVO.getVersion())) {
                partAllVO.setIsLatest("Y");
            } else {
                partAllVO.setIsLatest("N");
            }
        }

    }

    public List<PartRefDocVO> queryReferenceDocByPartList(Map<String, Object> map) {
        return (List)(!Objects.isNull(map) && map.containsKey("list") && !CollUtil.isEmpty((List)map.get("list")) ? this.typlmPartMapper.queryReferenceDocByPartList(map) : new ArrayList());
    }

    public List<DocDO> queryReferenceDocListByPartOidList(List<BigInteger> partOidList, BigInteger oid) {
        if (!CollUtil.isEmpty(partOidList) && !ObjectUtil.isEmpty(oid)) {
            UserDO user = TyAccountContext.getUser();
            return BatchQueryHelper.batchSplitQuery(partOidList, (list) -> {
                return this.typlmPartMapper.queryReferenceDocListByPartOidList(new ArrayList(list), user.getOid());
            });
        } else {
            return new ArrayList();
        }
    }

    public List<PartRefDocVO> queryReferenceDocByPartOidList(List<BigInteger> partOidList) {
        if (CollUtil.isEmpty(partOidList)) {
            return new ArrayList();
        } else {
            UserDO user = TyAccountContext.getUser();
            return BatchQueryHelper.batchSplitQuery(partOidList, (list) -> {
                return this.typlmPartMapper.queryReferenceDocByPartOidList((List)list, user.getOid());
            });
        }
    }

    public List<PartRefDocVO> queryDescriptionDocByPartList(List<PartDO> partDOList, BigInteger userOid) {
        Map<String, Object> map = new HashMap();
        map.put("list", partDOList);
        map.put("userid", userOid);
        return this.typlmPartMapper.queryDescriptionDocByPartList(map);
    }

    public List<PartRefDocVO> queryAllVersionDesDocByPart(List<PartDO> partDOList, BigInteger userOid) {
        Map<String, Object> map = new HashMap();
        map.put("list", partDOList);
        map.put("userid", userOid);
        map.put("allversion", "Y");
        return this.typlmPartMapper.queryDescriptionDocByPartList(map);
    }

    public List<PartDO> queryPartHistory(BigInteger oid, String versionType) {
        List<PartDO> resultList = new ArrayList();
        if (oid.compareTo(BigInteger.ZERO) != 0) {
            PartDO partDO = (PartDO)this.typlmPartMapper.selectByPrimaryKey(oid);
            if (Objects.nonNull(partDO)) {
                if (this.tySwitchConfig.isOpenMysqlSwitch()) {
                    resultList = this.typlmPartMapper.queryPartDOByMasteredOid(partDO.getMasteredoid(), StringUtils.isNotEmpty(versionType) && "allVersion".equalsIgnoreCase(versionType) ? PartConstant.LONG_ONE : null);
                } else {
                    Example example = new Example(PartDO.class, true, true);
                    Example.Criteria criteria = example.createCriteria();
                    criteria.andEqualTo("masteredoid", partDO.getMasteredoid());
                    if (StringUtils.isNotEmpty(versionType) && "allVersion".equalsIgnoreCase(versionType)) {
                        criteria.andEqualTo("islastiterated", PartConstant.LONG_ONE);
                    }

                    example.setOrderByClause("versionsort DESC,version DESC,CAST(iterationid as numeric) DESC,modifystamp desc");
                    resultList = this.typlmPartMapper.selectByExample(example);
                }
            }
        }

        return (List)resultList;
    }

    public List<PartDO> queryPartHistoryByParams(BigInteger oid) {
        List<PartDO> resultList = new ArrayList();
        if (oid.compareTo(BigInteger.ZERO) != 0) {
            PartDO partDO = (PartDO)this.typlmPartMapper.selectByPrimaryKey(oid);
            if (Objects.nonNull(partDO)) {
                Example example = new Example(PartDO.class, true, true);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("masteredoid", partDO.getMasteredoid());
                if (!TyplmEntityBaseUtil.isEmptyOid(partDO.getViewdefoid())) {
                    criteria.andEqualTo("viewdefoid", partDO.getViewdefoid());
                    if (StringUtils.isNotBlank(partDO.getVariation1())) {
                        criteria.andEqualTo("variation1", partDO.getVariation1());
                    }

                    if (StringUtils.isNotBlank(partDO.getVariation2())) {
                        criteria.andEqualTo("variation2", partDO.getVariation2());
                    }
                }

                if (this.tySwitchConfig.isOpenMysqlSwitch()) {
                    example.setOrderByClause("versionsort DESC,version DESC,CAST(iterationid as UNSIGNED) DESC,modifystamp desc");
                } else {
                    example.setOrderByClause("versionsort DESC,version DESC,CAST(iterationid as numeric) DESC,modifystamp desc");
                }

                resultList = this.typlmPartMapper.selectByExample(example);
            }
        }

        return (List)resultList;
    }

    public List<ObjectHistoryRecordVO> queryPartHistoryByPartList(List<PartDO> partList) {
        List<ObjectHistoryRecordVO> resultList = new ArrayList();
        Set<BigInteger> createOidList = new HashSet();
        Set<BigInteger> viewdefOidList = new HashSet();
        List<BigInteger> oids = new ArrayList();
        String otype = "";
        if (!CollectionUtils.isEmpty(partList)) {
            Iterator var7 = partList.iterator();

            while(var7.hasNext()) {
                PartDO pDo = (PartDO)var7.next();
                ObjectHistoryRecordVO vo = new ObjectHistoryRecordVO();
                vo.setOid(pDo.getOtype() + ":" + pDo.getOid());
                vo.setType("part");
                vo.setMajorVersion(pDo.getVersion());
                vo.setMinorVersion(pDo.getIterationid());
                vo.setWorkflowStateKey(pDo.getLifecyclestagekey());
                vo.setCreator(String.valueOf(pDo.getCreatoroid()));
                vo.setModifier(String.valueOf(pDo.getUpdatoroid()));
                vo.setOwner(String.valueOf(pDo.getOwneroid()));
                vo.setCreationTime(DateUtils.getDateString(pDo.getCreatestamp(), "yyyy-MM-dd HH:mm:ss"));
                vo.setModifyTime(DateUtils.getDateString(pDo.getModifystamp(), "yyyy-MM-dd HH:mm:ss"));
                vo.setPartView(String.valueOf(pDo.getViewdefoid()));
                vo.setPartViewOid(pDo.getViewdefoid());
                vo.setDescription(pDo.getDescription());
                vo.setEnglishDescription(pDo.getEnglishdescription());
                vo.setCheckInRemark(pDo.getIterationnote());
                vo.setCheckInOrCheckOut(pDo.getLockstateinfo());
                if (!"c/i".equalsIgnoreCase(pDo.getLockstateinfo()) && pDo.getLockeroid() != null) {
                    vo.setCheckoutBy(String.valueOf(pDo.getLockeroid()));
                }

                oids.add(pDo.getOid());
                otype = pDo.getOtype();
                resultList.add(vo);
                createOidList.add(pDo.getLockeroid());
                createOidList.add(pDo.getCreatoroid());
                createOidList.add(pDo.getUpdatoroid());
                viewdefOidList.add(pDo.getViewdefoid());
                createOidList.add(pDo.getOwneroid());
            }

            Map<String, String> itemRevision = this.typlmStatusValueService.queryStatusValueBydefKey(oids, otype, "Revision");
            this.setItemRevision(resultList, itemRevision);
            List<UserDO> userList = this.typlmUserService.queryAllUserByOids(new ArrayList(createOidList));
            List<ViewDefDO> viewList = this.typlmViewDefService.queryViewDefListByOid(new ArrayList(viewdefOidList));
            List<CTyEntityBaseDO> listDo = new ArrayList();
            listDo.addAll(viewList);
            CommonUtil.mergerData(userList, listDo, resultList);
        }

        return resultList;
    }

    private void setItemRevision(List<ObjectHistoryRecordVO> resultList, Map<String, String> itemRevision) {
        if (!CollectionUtils.isEmpty(itemRevision)) {
            Iterator var3 = itemRevision.entrySet().iterator();

            while(var3.hasNext()) {
                Map.Entry<String, String> mapEntry = (Map.Entry)var3.next();
                Iterator var5 = resultList.iterator();

                while(var5.hasNext()) {
                    ObjectHistoryRecordVO result = (ObjectHistoryRecordVO)var5.next();
                    String[] results = result.getOid().split(":");
                    if (((String)mapEntry.getKey()).equals(results[1])) {
                        result.setItemRevision((String)mapEntry.getValue());
                    }
                }
            }
        }

    }

    public List<PartMasterDO> queryPartMasterByPartNumber(String partNumber) {
        Example ex = new Example(PartMasterDO.class, true, true);
        Example.Criteria criteria = ex.createCriteria();
        criteria.andEqualTo("partnumber", partNumber);
        return this.typlmPartMasterMapper.selectByExample(ex);
    }

    public int updatePart(PartDO partDO, BigInteger userID) {
        if (Objects.nonNull(partDO)) {
            partDO.setUpdatestamp(new Date());
            partDO.setModifystamp(new Date());
            partDO.setLastupdatestamp(new Date());
            partDO.setUpdatecount(partDO.getUpdatecount() + 1L);
            partDO.setUpdatoroid(userID);
            partDO.setUpdatorotype("ty.inteplm.org.CTyUser");
        }

        return this.typlmPartMapper.updateByPrimaryKey(partDO);
    }

    public int updatePartMaster(PartMasterDO partMasterDO) {
        if (Objects.nonNull(partMasterDO)) {
            Date date = new Date();
            partMasterDO.setUpdatestamp(date);
            partMasterDO.setModifystamp(date);
            partMasterDO.setUpdatecount(partMasterDO.getUpdatecount() + 1L);
        }

        return this.typlmPartMasterMapper.updateByPrimaryKey(partMasterDO);
    }

    public List<TyPartAllVO> queryPartByConditionWithoutPage(PagePartQuery query) {
        String partNumber = query.getPartNumber();
        if (StringUtils.isNotEmpty(partNumber)) {
            if (partNumber.contains(",")) {
                if (this.setPartNumbers(query, partNumber)) {
                    return new ArrayList();
                }
            } else if (!partNumber.contains(",") && "1".equals(query.getIsExactQuery())) {
                query.setPartNumber("'" + partNumber + "'");
            } else {
                partNumber = partNumber.toUpperCase(Locale.ROOT);
                query.setPartNumber(partNumber);
            }
        }

        return this.typlmPartQueryMapper.queryPartByConditionWithoutPage(query);
    }

    private boolean setPartNumbers(PagePartQuery query, String partNumber) {
        query.setIsExactQuery("1");
        String[] partNumbers = partNumber.split("[,]");
        if (partNumbers.length > 1000) {
            return true;
        } else {
            StringBuilder newPartNumberStr = new StringBuilder();
            String[] var5 = partNumbers;
            int var6 = partNumbers.length;

            for(int var7 = 0; var7 < var6; ++var7) {
                String s = var5[var7];
                if (s.length() < 4) {
                    return true;
                }

                newPartNumberStr.append("'").append(s).append("'").append(",");
            }

            query.setPartNumber(newPartNumberStr.toString().substring(0, newPartNumberStr.length() - 1));
            return false;
        }
    }

    public List<PartDO> queryPartByNumber(String partNumber, String version, String view) {
        List<PartMasterDO> master = this.queryPartMasterByPartNumber(partNumber);
        if (!CollectionUtils.isEmpty(master)) {
            Example ex = new Example(PartDO.class, true, true);
            Example.Criteria criteria = ex.createCriteria();
            PartMasterDO partMaster = (PartMasterDO)master.get(0);
            criteria.andEqualTo("masteredoid", partMaster.getOid());
            criteria.andEqualTo("masteredotype", partMaster.getOtype());
            if (this.checkView(view, criteria)) {
                return new ArrayList();
            } else {
                if (StringUtils.isNotEmpty(version)) {
                    if (version.indexOf(46) > -1) {
                        String[] versionStrs = version.split("[.]");
                        criteria.andEqualTo("version", versionStrs[0]);
                        criteria.andEqualTo("iterationid", versionStrs[1]);
                    } else {
                        criteria.andEqualTo("version", version);
                    }
                } else {
                    criteria.andEqualTo("islastiterated", 1);
                }

                if (this.tySwitchConfig.isOpenMysqlSwitch()) {
                    ex.setOrderByClause("versionsort DESC,version DESC, cast(iterationid as UNSIGNED) DESC ");
                } else {
                    ex.setOrderByClause("versionsort DESC,version DESC, CAST(iterationid as numeric) DESC ");
                }

                return this.typlmPartMapper.selectByExample(ex);
            }
        } else {
            return new ArrayList();
        }
    }

    public List<PartDO> queryPartByMasterIdAndView(List<BigInteger> masterIds, BigInteger viewId) {
        if (!CollectionUtils.isEmpty(masterIds) && !Objects.isNull(viewId) && !BigInteger.ZERO.equals(viewId)) {
            List<PartDO> resultList = new ArrayList();
            List<List<BigInteger>> lists = CommonUtil.subObjectList(masterIds, 500);
            Iterator var5 = lists.iterator();

            while(var5.hasNext()) {
                List<BigInteger> masterIdList = (List)var5.next();
                Example ex = new Example(PartDO.class, true, true);
                Example.Criteria criteria = ex.createCriteria();
                criteria.andIn("masteredoid", masterIdList);
                criteria.andEqualTo("masteredotype", "ty.inteplm.part.CTyPartMaster");
                criteria.andEqualTo("viewdefoid", viewId);
                criteria.andEqualTo("viewdefotype", "ty.inteplm.view.CTyViewDef");
                criteria.andEqualTo("islastiterated", 1);
                List<PartDO> partDOS = this.typlmPartMapper.selectByExample(ex);
                resultList.addAll(partDOS);
            }

            return resultList;
        } else {
            return new ArrayList();
        }
    }

    public List<ObjectHistoryRecordVO> queryPartByNumberAndView(String partNumber, String view, boolean versionFlag) {
        List partList;
        if (versionFlag) {
            partList = this.queryPartByNumberAndView(partNumber, view, "allVersion");
        } else {
            partList = this.queryPartByNumberAndView(partNumber, view, "");
        }

        return this.queryPartHistoryByPartList(partList);
    }

    public List<PartDO> queryPartByNumberAndView(String partNumber, String view, String versionType) {
        List<PartMasterDO> master = this.queryPartMasterByPartNumber(partNumber);
        if (!CollectionUtils.isEmpty(master)) {
            Example ex = new Example(PartDO.class, true, true);
            Example.Criteria criteria = ex.createCriteria();
            PartMasterDO partMaster = (PartMasterDO)master.get(0);
            criteria.andEqualTo("masteredoid", partMaster.getOid());
            criteria.andEqualTo("masteredotype", partMaster.getOtype());
            if (this.checkView(view, criteria)) {
                return new ArrayList();
            } else {
                if (StringUtils.isNotEmpty(versionType) && "allVersion".equalsIgnoreCase(versionType)) {
                    criteria.andEqualTo("islastiterated", PartConstant.LONG_ONE);
                }

                if (this.tySwitchConfig.isOpenMysqlSwitch()) {
                    ex.setOrderByClause("versionsort DESC,version DESC,CAST(iterationid as UNSIGNED) DESC,modifystamp desc");
                } else {
                    ex.setOrderByClause("versionsort DESC,version DESC,CAST(iterationid as numeric) DESC,modifystamp desc");
                }

                return this.typlmPartMapper.selectByExample(ex);
            }
        } else {
            return new ArrayList();
        }
    }

    public List<PartDO> queryPartByNumber(String partNumber) {
        return this.typlmPartMapper.queryPartByNumber(partNumber);
    }

    private boolean checkView(String view, Example.Criteria criteria) {
        if (StringUtils.isNotEmpty(view)) {
            List<ViewDefDO> views = this.typlmViewDefService.queryViewByName(view);
            if (CollectionUtils.isEmpty(views)) {
                return true;
            }

            criteria.andEqualTo("viewdefoid", ((ViewDefDO)views.get(0)).getOid());
            criteria.andEqualTo("viewdefotype", ((ViewDefDO)views.get(0)).getOtype());
        }

        return false;
    }

    public PartMasterDO queryPartMasterDO(PartMasterDO partMasterDO) {
        return (PartMasterDO)this.typlmPartMasterMapper.selectOne(partMasterDO);
    }

    public PartMasterDO queryPartMasterDOByOID(BigInteger oid) {
        return (PartMasterDO)this.typlmPartMasterMapper.selectByPrimaryKey(oid);
    }

    public PageInfo<MyCreateObjVO> queryPartByUesrOld(MyCreateObjQuery myCreateObjQuery) {
        if (ObjectUtils.isEmpty(myCreateObjQuery) || StringUtils.isEmpty(myCreateObjQuery.getUserName())) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"UserName"});
        }

        myCreateObjQuery.checkStartIndexRange();
        UserDO user = this.typlmUserService.queryUserByName(myCreateObjQuery.getUserName());
        if (user == null) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{myCreateObjQuery.getUserName()});
            return new PageInfo();
        } else {
            myCreateObjQuery.setUserOID(user.getOid());
            TableNameCheckUtil.checkSortIsIegalized(myCreateObjQuery.getSort());
            int count = this.typlmPartQueryMapper.queryCountByUesrOld(myCreateObjQuery);
            List<MyCreateObjVO> myCreateObjVOS = this.typlmPartQueryMapper.queryPartByUesrOld(myCreateObjQuery);
            PageInfo<MyCreateObjVO> page = new PageInfo(myCreateObjVOS);
            page.setPageSize(myCreateObjQuery.getPageSize());
            page.setPageNum(myCreateObjQuery.getCurPage());
            page.setTotal((long)count);
            return page;
        }
    }

    public int updatePart(PartDO partDO) {
        if (Objects.nonNull(partDO)) {
            partDO.setUpdatestamp(new Date());
            partDO.setModifystamp(new Date());
            partDO.setLastupdatestamp(new Date());
            partDO.setUpdatecount(partDO.getUpdatecount() + 1L);
            partDO.setUpdatorotype("ty.inteplm.org.CTyUser");
        }

        return this.typlmPartMapper.updateByPrimaryKey(partDO);
    }

    public PartDO savePartAndMaster(TyPartAndMasterDTO partAndMasterDTO) {
        BigInteger partOid = partAndMasterDTO.getOid();
        String partOtype = partAndMasterDTO.getOtype();
        TyplmLoggerUtil.debug(log, () -> {
            return "通过id查询零部件 ==> partoid:【{}】, partOtype:【{}】";
        }, () -> {
            return new Object[]{String.valueOf(partOid), partOtype};
        });
        PartDO partDO = this.queryPartByOid(partOid, partOtype);
        if (TyAccountContext.isDebug()) {
            log.info("通过id查询零部件结果 <== partDO:【{}】", JSONObject.toJSONString(partDO));
        }

        partDO = this.savePartAndMaster(partAndMasterDTO, partDO);
        return partDO;
    }

    public PartDO savePartAndMaster(TyPartAndMasterDTO partAndMasterDTO, PartDO partDO) {
        String loginUserId = partAndMasterDTO.getLogUserID();
        if (StringUtils.isEmpty(partAndMasterDTO.getLogUserID())) {
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{loginUserId})));
        } else if (Objects.isNull(partDO)) {
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"partDO"})));
        } else {
            BigInteger partoid = partAndMasterDTO.getOid();
            if (partAndMasterDTO.getDefaultunitkey() != null) {
                this.verifyUnit(partAndMasterDTO.getDefaultunitkey());
            }

            TyplmLoggerUtil.debug(log, () -> {
                return "校验修改权限 ==> partAndMasterDTO:【{}】, partDO:【{}】, loginUserId:【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(partAndMasterDTO), JSONObject.toJSONString(partDO), loginUserId};
            });
            this.judegPartPermission(partAndMasterDTO, partDO, loginUserId);
            if (partDO.getOid().compareTo(BigInteger.ZERO) != 0) {
                TyplmLoggerUtil.debug(log, () -> {
                    return "设置修改人 ==> partAndMasterDTO:【{}】, partDO:【{}】, loginUserId:【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partAndMasterDTO), JSONObject.toJSONString(partDO), loginUserId};
                });
                this.setModifyer(partAndMasterDTO, partDO, partAndMasterDTO.getLogUserID());
                TyplmLoggerUtil.debug(log, () -> {
                    return "设置所有者 ==> partAndMasterDTO:【{}】, partDO:【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partAndMasterDTO), JSONObject.toJSONString(partDO)};
                });
                this.setOwnerNew(partAndMasterDTO, partDO);
                TyplmLoggerUtil.debug(log, () -> {
                    return "查询主对象 ==> masteredoid:【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partDO.getMasteredoid())};
                });
                PartMasterDO partMasterDO = this.queryPartMasterDOByOID(partDO.getMasteredoid());
                TyplmLoggerUtil.debug(log, () -> {
                    return "查询主对象 <== partMasterDO:【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partMasterDO)};
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "设置并校验可配置可折叠 ==> partMasterDO:【{}】, partAndMasterDTO: 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partMasterDO), JSONObject.toJSONString(partAndMasterDTO)};
                });
                this.checkGenericTypeAndCollapsible(partMasterDO, partAndMasterDTO);
                PartMasterDO partMasterDOTemp = new PartMasterDO();
                BeanUtils.copyProperties(partMasterDO, partMasterDOTemp);
                TyplmLoggerUtil.debug(log, () -> {
                    return "设置其他属性 ==> partAndMasterDTO: 【{}】, partDO:【{}】, partMasterDO:【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partAndMasterDTO), JSONObject.toJSONString(partDO), JSONObject.toJSONString(partMasterDO)};
                });
                this.setPartinfo(partAndMasterDTO, partDO, partMasterDO);
                TyplmLoggerUtil.debug(log, () -> {
                    return "设置其他属性 <== partAndMasterDTO: 【{}】, partDO:【{}】, partMasterDO:【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partAndMasterDTO), JSONObject.toJSONString(partDO), JSONObject.toJSONString(partMasterDO)};
                });
                if (StringUtils.isNotEmpty(partAndMasterDTO.getLifecycleTemplate())) {
                    this.queryAndSetCreatePartLifecycle(partAndMasterDTO, partDO, new TypeDO());
                }

                this.setContainerAndFolder(partDO, partAndMasterDTO);
                TyplmLoggerUtil.debug(log, () -> {
                    return "更新零部件入参 ==> partDO: 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partDO)};
                });
                this.updatePart(partDO);
                if (!partMasterDO.equals(partMasterDOTemp)) {
                    TyplmLoggerUtil.debug(log, () -> {
                        return "更新零部件主对象入参 ==> partMasterDO: 【{}】";
                    }, () -> {
                        return new Object[]{JSONObject.toJSONString(partMasterDO)};
                    });
                    this.updatePartMaster(partMasterDO);
                }

                return partDO;
            } else {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_PART_NOT_FOUND, new String[]{partoid.toString()})));
            }
        }
    }

    private void judegPartPermission(TyPartAndMasterDTO partAndMasterDTO, PartDO partDO, String loginUserId) {
        PartDO partSourceDo;
        if ("wrk".equalsIgnoreCase(partDO.getLockstateinfo())) {
            partSourceDo = this.queryPartByOid(partDO.getSourceiterationoid(), partDO.getSourceiterationotype());
        } else {
            partSourceDo = partDO;
        }

        if (partAndMasterDTO.getIsCheckRight()) {
            UserDO userDO = this.typlmUserService.queryUserByKey(new BigInteger(loginUserId));
            this.typlmPermissionsUtil.checkObjectPermission(userDO, Collections.singletonList(partSourceDo), Collections.singletonList("修改"));
        }
    }

    private void setModifyer(TyPartAndMasterDTO partAndMasterDTO, PartDO partDO, String loginUserId) {
        if (StringUtils.isNotEmpty(partAndMasterDTO.getModifierName())) {
            UserDO userDO = this.typlmUserService.queryUserByName(partAndMasterDTO.getModifierName());
            if (Objects.isNull(userDO)) {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{partAndMasterDTO.getModifierName()})));
            }

            if ("wrk".equalsIgnoreCase(partDO.getLockstateinfo()) && !String.valueOf(userDO.getOid()).equalsIgnoreCase(loginUserId)) {
                UserDO loginUser = this.typlmUserService.queryUserByKey(new BigInteger(loginUserId));
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_PARAMETER_MODIFIER_MUST_SAME_AS_CHECKER, new String[]{loginUser.getName()})));
            }

            partDO.setUpdatoroid(userDO.getOid());
            partDO.setUpdatorotype(userDO.getOtype());
        } else {
            partDO.setUpdatoroid(new BigInteger(loginUserId));
            partDO.setUpdatorotype("ty.inteplm.org.CTyUser");
        }

    }

    private void setOwner(TyPartAndMasterDTO partAndMasterDTO, PartDO partDO) {
        if (StringUtils.isNotEmpty(partAndMasterDTO.getOwnerName())) {
            UserDO userDO = this.typlmUserService.queryUserByName(partAndMasterDTO.getOwnerName());
            if (Objects.isNull(userDO)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{"owner:" + partAndMasterDTO.getOwnerName()});
                return;
            }

            partDO.setOwneroid(userDO.getOid());
            partDO.setOwnerotype(userDO.getOtype());
        }

    }

    private void setOwnerNew(TyPartAndMasterDTO partAndMasterDTO, PartDO partDO) {
        if (null != partAndMasterDTO.getOwnerName()) {
            if (StringUtils.isNotBlank(partAndMasterDTO.getOwnerName())) {
                UserDO userDO = this.typlmUserService.queryUserByName(partAndMasterDTO.getOwnerName());
                if (Objects.isNull(userDO)) {
                    TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{"owner:" + partAndMasterDTO.getOwnerName()});
                    return;
                }

                partDO.setOwneroid(userDO.getOid());
                partDO.setOwnerotype(userDO.getOtype());
            } else {
                partDO.setOwneroid((BigInteger)null);
                partDO.setOwnerotype("");
            }

        }
    }

    private void verifyUnit(String unitKey) {
        TyplmLoggerUtil.debug(log, () -> {
            return "校验单位是否在枚举中 ==> unitKey :【{}】";
        }, () -> {
            return new Object[]{unitKey};
        });
        boolean isUnitInEnum = CollectionUtils.isEmpty(this.typlmEnumerationService.queryUnitAttributesValue(unitKey, "unit"));
        if (isUnitInEnum) {
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_ATTRIBUTE_UNIT_NOTIN_RANGE, new String[]{unitKey})));
        }
    }

    private void setPartinfo(TyPartAndMasterDTO partAndMasterDTO, PartDO cTyPart, PartMasterDO partMasterDO) {
        this.setOwner(partAndMasterDTO, cTyPart);
        partMasterDO.setDefaultunitkey(StringUtil.defaultString(partAndMasterDTO.getDefaultunitkey(), partMasterDO.getDefaultunitkey()));
        partMasterDO.setName(StringUtil.defaultString(partAndMasterDTO.getMasterName(), partMasterDO.getName()));
        cTyPart.setEnglishdescription(StringUtil.defaultString(partAndMasterDTO.getEnglishdescription(), cTyPart.getEnglishdescription()));
        cTyPart.setOrgcode(StringUtil.defaultString(partAndMasterDTO.getOrgcode(), cTyPart.getOrgcode()));
        cTyPart.setSourcekey(StringUtil.defaultString(partAndMasterDTO.getSourcekey(), cTyPart.getSourcekey()));
        cTyPart.setIterationnote(StringUtil.defaultString(partAndMasterDTO.getIterationnote(), ""));
        if (CommonUtil.isBigIntegerZeroOrNull(partAndMasterDTO.getTypeid())) {
            cTyPart.setTypeid(partAndMasterDTO.getTypeid());
        }

        if (CommonUtil.isLongZeroOrNull(partAndMasterDTO.getResourcecategroyid())) {
            cTyPart.setResourcecategroyid(partAndMasterDTO.getResourcecategroyid());
        }

        this.setIteratedName(partAndMasterDTO, cTyPart);
        this.setPartRelObjectID(partAndMasterDTO, cTyPart);
        partMasterDO.setGenerictype(StringUtil.getDefaultStringValue(partAndMasterDTO.getGenerictype(), partMasterDO.getGenerictype()));
        partMasterDO.setCollapsible(partAndMasterDTO.getCollapsible());
        cTyPart.setParttypekey(StringUtil.getDefaultStringValue(partAndMasterDTO.getParttypekey(), cTyPart.getParttypekey()));
        if (StringUtil.isNotEmpty(partAndMasterDTO.getHidePartInstructure())) {
            partMasterDO.setHidepartinstructure(Long.parseLong(partAndMasterDTO.getHidePartInstructure()));
        }

    }

    private void setContainerAndFolder(PartDO cTyPart, TyPartAndMasterDTO tyPartAndMasterDTO) {
        TyplmLoggerUtil.debug(log, () -> {
            return "设置容器及文件夹入参 ==> cTyPart: 【{}】, tyPartAndMasterDTO:【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(cTyPart), JSONObject.toJSONString(tyPartAndMasterDTO)};
        });
        String containerName = tyPartAndMasterDTO.getContainerName();
        String containerType = tyPartAndMasterDTO.getContainerType();
        String folderName = tyPartAndMasterDTO.getFolderPath();
        String containerOid = tyPartAndMasterDTO.getContainerID();
        String folderid = tyPartAndMasterDTO.getFolderId();
        if (!this.verifyParams(containerName, containerType, folderName, containerOid, folderid)) {
            ContainerVO containerVO = null;
            if (StringUtils.isNotBlank(containerName) || StringUtils.isNotBlank(containerOid)) {
                TyplmLoggerUtil.debug(log, () -> {
                    return "查询容器信息 ==> containerType: 【{}】, containerOid:【{}】, containerName:【{}】";
                }, () -> {
                    return new Object[]{containerType, containerOid, containerName};
                });
                containerVO = this.typlmContainerService.getContainerVO(containerType, containerOid, containerName);
                if (TyAccountContext.isDebug()) {
                    log.info("查询容器信息 <== containerVO: 【{}】", JSONObject.toJSONString(containerVO));
                }

                if (Objects.nonNull(containerVO)) {
                    cTyPart.setCabinetoid(new BigInteger(containerVO.getDefaultcabinetoid()));
                    cTyPart.setCabinetotype(containerVO.getDefaultcabinetotype());
                }
            }

            TyplmLoggerUtil.debug(log, () -> {
                return "查询文件柜或者文件夹信息 ==> Cabinetoid: 【{}】, Cabinetotype:【{}】, folderid:【{}】, folderName:【{}】";
            }, () -> {
                return new Object[]{String.valueOf(cTyPart.getCabinetoid()), cTyPart.getCabinetotype(), folderid, folderName};
            });
            CTyEntityBaseDO entityBaseDO = this.typlmSubFolderLinkService.getCabinetOrSubFolderDO(cTyPart.getCabinetoid(), cTyPart.getCabinetotype(), folderid, folderName);
            TyplmLoggerUtil.debug(log, () -> {
                return "查询文件柜或者文件夹信息返回结果 <== entityBaseDO: 【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(entityBaseDO)};
            });
            TyplmLoggerUtil.debug(log, () -> {
                return "查询上载对象 ==> partOid: 【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(Arrays.asList(cTyPart.getOid()))};
            });
            Map<BigInteger, List<CADInitialCheckinDataDO>> initialCheckinDataMap = this.typlmCADInitialCheckinDataService.queryCADInitialCheckinDataByAObj(Arrays.asList(cTyPart.getOid()));
            TyplmLoggerUtil.debug(log, () -> {
                return "查询上载对象返回结果 <== initialCheckinDataMap: 【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(initialCheckinDataMap)};
            });
            if (initialCheckinDataMap.containsKey(cTyPart.getOid())) {
                this.setUploadPartContainerAndFolder(containerVO, entityBaseDO, cTyPart);
            } else {
                this.setPartContainerAndFolder(containerVO, entityBaseDO, cTyPart);
            }

        }
    }

    private boolean verifyParams(String containerName, String containerType, String folderName, String containerOid, String folderid) {
        boolean flag = StringUtils.isBlank(containerName) && StringUtils.isBlank(containerOid) && StringUtils.isBlank(folderid) && StringUtils.isBlank(folderName);
        if (flag) {
            return true;
        } else {
            boolean containerFlag = StringUtils.isBlank(containerType) && (StringUtils.isNotBlank(containerName) || StringUtils.isNotBlank(containerOid));
            boolean folderFlag = (StringUtils.isNotBlank(containerName) || StringUtils.isNotBlank(containerOid)) && StringUtils.isBlank(folderid) && StringUtils.isBlank(folderName);
            if (containerFlag) {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_CONTAINER_TYPE_ERROR, new String[]{"containerType"})));
            } else if (folderFlag) {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.ACC_PARAMETER_NOT_FOUND, new String[]{"folderId,folderName"})));
            } else {
                return false;
            }
        }
    }

    public List<PartMasterDO> queryPartMasterList(List<String> partNumberList) {
        long begin = System.currentTimeMillis();
        List<PartMasterDO> partMasterDOList = new ArrayList();
        if (CollUtil.isNotEmpty(partNumberList)) {
            List<List<String>> subLists = ListUtils.partition(partNumberList, 1000);
            Iterator var6 = subLists.iterator();

            while(var6.hasNext()) {
                List<String> subList = (List)var6.next();
                partMasterDOList.addAll(this.typlmPartMapper.queryPartMasterList(subList));
            }
        }

        log.info("queryPartMasterList total time: " + (System.currentTimeMillis() - begin));
        return partMasterDOList;
    }

    public List<PartDO> queryPartByIDs(List<String> oids) {
        List<PartDO> result = new ArrayList();
        if (CollUtil.isEmpty(oids)) {
            return result;
        } else {
            List<BigInteger> oidList = new ArrayList();
            Iterator var4 = oids.iterator();

            while(var4.hasNext()) {
                String str = (String)var4.next();
                if (StringUtils.isNotEmpty(str)) {
                    oidList.add(new BigInteger(str));
                }
            }

            List<List<BigInteger>> split = CollUtil.split(CollUtil.distinct(oidList), 800);
            Iterator var9 = split.iterator();

            while(var9.hasNext()) {
                List<BigInteger> list = (List)var9.next();
                Example ex = this.getExample(list);
                result.addAll(this.typlmPartMapper.selectByExample(ex));
            }

            return result;
        }
    }

    public List<PartDO> queryAccessPartByIDs(List<String> oids) {
        List<BigInteger> oidList = new ArrayList();
        Iterator var3 = oids.iterator();

        while(var3.hasNext()) {
            String str = (String)var3.next();
            if (StringUtils.isNotEmpty(str)) {
                oidList.add(new BigInteger(str));
            }
        }

        return this.typlmPartMapper.queryAccessPartByOids(oidList);
    }

    private Example getExample(List<BigInteger> oidList) {
        Example ex = new Example(PartDO.class, true, true);
        if (!CollectionUtils.isEmpty(oidList)) {
            Example.Criteria criteria = ex.createCriteria();
            criteria.andIn("oid", oidList);
        }

        return ex;
    }

    public List<PartDO> queryPartByBigIntegerIDs(List<BigInteger> oids) {
        List<PartDO> partDOS = new ArrayList();
        if (CollUtil.isEmpty(oids)) {
            return partDOS;
        } else {
            List<List<BigInteger>> split = CollUtil.split(CollUtil.distinct(oids), 500);
            Iterator var4 = split.iterator();

            while(var4.hasNext()) {
                List<BigInteger> list = (List)var4.next();
                partDOS.addAll(this.typlmPartMapper.selectPartDOByOids(list));
            }

            return partDOS;
        }
    }

    public List<PartDO> queryPartByBigIntegerIDsCheckExist(List<BigInteger> oids) {
        if (CollectionUtils.isEmpty(oids)) {
            return Collections.emptyList();
        } else {
            List<PartDO> partDOList = this.queryPartByBigIntegerIDs(oids);
            EntityBaseUtil.checkNotExist(oids, partDOList);
            return partDOList;
        }
    }

    public List<HashMap> queryMultiObjectIDByContion(TyQueryMultiObjectOIDByContion tyQueryMultiObjectOIDByContion) {
        return this.typlmPartMapper.queryMultiObjectIDByContion(tyQueryMultiObjectOIDByContion);
    }

    private int getObjectOidByName(PartDO cTyPart, String keyName, List<HashMap> hashMapList) {
        int cnt = 0;
        if (CollectionUtils.isEmpty(hashMapList)) {
            return cnt;
        } else {
            for(int j = 0; j < hashMapList.size(); ++j) {
                HashMap reHash = (HashMap)hashMapList.get(j);
                String strOid = reHash.get("OID").toString();
                String strOtype = reHash.get("OTYPE").toString();
                if (strOid.contains(keyName) && strOid.contains(":")) {
                    List<String> arrOids = Arrays.asList(strOid.split(":"));
                    if (arrOids.size() != 2) {
                        break;
                    }

                    if (!StringUtils.isEmpty((CharSequence)arrOids.get(1))) {
                        BigInteger oid = new BigInteger((String)arrOids.get(1));
                        this.setPartinfo(cTyPart, keyName, oid, strOtype);
                        cnt = 1;
                        break;
                    }
                }
            }

            return cnt;
        }
    }

    private void setPartinfo(PartDO cTyPart, String keyName, BigInteger oid, String otype) {
        if (keyName.contains("modifyerOID")) {
            cTyPart.setUpdatoroid(oid);
            cTyPart.setUpdatorotype(otype);
        }

        if (keyName.contains("ownerOID")) {
            cTyPart.setOwneroid(oid);
            cTyPart.setOwnerotype(otype);
        }

        if (keyName.contains("viewOID")) {
            cTyPart.setViewdefoid(oid);
            cTyPart.setViewdefotype(otype);
        }

        if (keyName.contains("lifecycleTemplateOID")) {
            cTyPart.setLifecycletemplateoid(oid);
            cTyPart.setLifecycletemplateotype(otype);
        }

        if (keyName.contains("productOID") || keyName.contains("libraryOID")) {
            cTyPart.setContaineroid(oid);
            cTyPart.setContainerotype(otype);
        }

    }

    public void judgePartAboutEnum(PartEnumDTO partEnumDTO) {
        List<String> enumNames = new ArrayList();
        enumNames.add("unit");
        enumNames.add("AssemblyMode");
        Map<String, List<String>> enumInfos = this.typlmEnumerationItemService.queryEnumerationItemByDef(enumNames);
        Iterator var4 = enumInfos.entrySet().iterator();

        while(var4.hasNext()) {
            Map.Entry<String, List<String>> enumInfo = (Map.Entry)var4.next();
            switch ((String)enumInfo.getKey()) {
                case "unit":
                    this.judgeEnum(enumInfo, enumInfo.getKey(), partEnumDTO.getDefaultunitkey());
                    break;
                case "AssemblyMode":
                    this.judgeEnum(enumInfo, enumInfo.getKey(), partEnumDTO.getParttypekey());
            }
        }

    }

    private void judgeEnum(Map.Entry<String, List<String>> enumInfo, String key, String enumValue) {
        if (!StringUtils.isEmpty(enumValue)) {
            if (!((List)enumInfo.getValue()).contains(enumValue)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_CONSTRAINT_VALUE_ENUM, new String[]{enumValue, key});
            }

        }
    }

    public PartDO insertPart(TyPartAndMasterDTO partVO, UserDO user) {
        TyplmLoggerUtil.debug(log, () -> {
            return "是否上载 ==> isUpload :【{}】";
        }, () -> {
            return new Object[]{partVO.getIsUpload()};
        });
        if (!"true".equalsIgnoreCase(partVO.getIsUpload())) {
            this.verifyParams(partVO);
        }

        if (StringUtils.isNotEmpty(partVO.getDefaultunitkey())) {
            this.verifyUnit(partVO.getDefaultunitkey());
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "获取容器对象 ==>  containerOtype :【{}】, containerOid :【{}】, containerName :【{}】";
        }, () -> {
            return new Object[]{partVO.getContainerType(), partVO.getContainerID(), partVO.getContainerName()};
        });
        ContainerVO containerVO = this.typlmContainerService.getContainerVO(partVO.getContainerType(), partVO.getContainerID(), partVO.getContainerName());
        TyplmLoggerUtil.debug(log, () -> {
            return "获取容器对象返回 ==>  containerVO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(containerVO)};
        });
        partVO.setContainerID(containerVO.getOid());
        partVO.setContainerType(containerVO.getOtype());
        TyplmLoggerUtil.debug(log, () -> {
            return "通过编码查询主对象 ==>  partMasterNumber :【{}】";
        }, () -> {
            return new Object[]{partVO.getPartMasterNumber()};
        });
        List<PartMasterDO> partMasterDOS = this.queryPartMasterByPartNumber(partVO.getPartMasterNumber());
        TyplmLoggerUtil.debug(log, () -> {
            return "通过编码查询主对象返回 <==  partMasterDOS :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partMasterDOS)};
        });
        if (!CollectionUtils.isEmpty(partMasterDOS) && BooleanUtils.isTrue(partVO.getCreateMaster())) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_PART_ALREADY_EXISTS_IN_THE_SYSTEM, new String[]{partVO.getPartMasterNumber()});
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "校验可配置模块和可折叠 ==>  partVO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partVO)};
        });
        this.checkGenericTypeAndCollapsible((PartMasterDO)null, partVO);
        BigInteger partOid = Objects.isNull(partVO.getOid()) ? this.snowflakeIdComponent.getInstance().nextId() : partVO.getOid();
        Date newDate = new Date();
        TyplmLoggerUtil.debug(log, () -> {
            return "打包构建主对象 ==>  partVO :【{}】, partOid :【{}】, newDate :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partVO), String.valueOf(partOid), JSONObject.toJSONString(newDate)};
        });
        PartMasterDO partMasterDO = BooleanUtils.isFalse(partVO.getCreateMaster()) ? (PartMasterDO)partMasterDOS.get(0) : this.packagePartMasterVO(partVO, partOid, newDate);
        if (BooleanUtils.isFalse(partVO.getCreateMaster())) {
            AccessJudgeDTO judgeDTO = new AccessJudgeDTO();
            List<TypeVueVO> typeVueVOS = this.typlmTypeExtService.queryTypeByIds(Collections.singletonList(partVO.getTypeoid()));
            Map<BigInteger, String> typeNameMap = (Map)typeVueVOS.stream().collect(Collectors.toMap(TypeDO::getOid, TypeDO::getName, (k1, k2) -> {
                return k1;
            }));
            judgeDTO.setObjType((String)typeNameMap.getOrDefault(partVO.getTypeoid(), String.valueOf(partVO.getTypeoid())));
            judgeDTO.setDomainOid(CommonUtil.stringToBigIntegers(containerVO.getDomainoid()));
            judgeDTO.setPermissionName("新建视图版本");
            judgeDTO.setUserDO(user);
            this.typlmPermissionsUtil.checkPolicyRightByBatch(Collections.singletonList(judgeDTO));
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "打包构建主对象 <==  partMasterDO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partMasterDO)};
        });
        partMasterDO.setContaineroid(StringUtils.isNotEmpty(containerVO.getOid()) ? new BigInteger(containerVO.getOid()) : BigInteger.ZERO);
        partMasterDO.setContainerotype(containerVO.getOtype());
        OrgContainerDO orgContainerDO = this.getPartOrgContainerDO(partMasterDO);
        if (orgContainerDO != null) {
            partMasterDO.setOrgoid(orgContainerDO.getOrgoid());
            partMasterDO.setOrgotype(orgContainerDO.getOrgotype());
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "打包构建版本对象 ==>  partVO :【{}】, partMasterDO :【{}】, partOid :【{}】, newDate :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partVO), JSONObject.toJSONString(partMasterDO), String.valueOf(partOid), JSONObject.toJSONString(newDate)};
        });
        PartDO partDO = this.packagePartVO(partVO, partMasterDO, partOid, newDate);
        TyplmLoggerUtil.debug(log, () -> {
            return "打包构建版本对象结果 <==  partDO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partDO)};
        });
        TypeDO typeDO = this.setPartType(partVO, partDO);
        this.queryAndSetCreatePartLifecycle(partVO, partDO, typeDO);
        TyplmLoggerUtil.debug(log, () -> {
            return "获取文件夹或者文件柜 ==> 文件柜ID :【{}】, 文件柜otype :【{}】,文件夹ID :【{}】,文件夹path :【{}】";
        }, () -> {
            return new Object[]{containerVO.getDefaultcabinetoid(), containerVO.getDefaultcabinetotype(), partVO.getFolderId(), partVO.getFolderPath()};
        });
        CTyEntityBaseDO entityBaseDO = this.typlmSubFolderLinkService.getCabinetOrSubFolderDO(this.convertStringToBigInteger("defaultcabinetoid", containerVO.getDefaultcabinetoid()), containerVO.getDefaultcabinetotype(), partVO.getFolderId(), partVO.getFolderPath());
        TyplmLoggerUtil.debug(log, () -> {
            return "获取文件夹或者文件柜结果 <== entityBaseDO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(entityBaseDO)};
        });
        if ("true".equalsIgnoreCase(partVO.getIsUpload())) {
            TyplmLoggerUtil.debug(log, () -> {
                return "上载情况下设置容器跟文件夹 ==> containerVO :【{}】,entityBaseDO :【{}】,partDO :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(containerVO), JSONObject.toJSONString(entityBaseDO), JSONObject.toJSONString(partDO)};
            });
            this.setUploadPartContainerAndFolder(containerVO, entityBaseDO, partDO);
        } else {
            TyplmLoggerUtil.debug(log, () -> {
                return "非上载情况下设置容器跟文件夹 ==> containerVO :【{}】,entityBaseDO :【{}】,partDO :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(containerVO), JSONObject.toJSONString(entityBaseDO), JSONObject.toJSONString(partDO)};
            });
            this.setPartContainerAndFolder(containerVO, entityBaseDO, partDO);
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "校验创建权限 ==> containerVO :【{}】,partDO :【{}】,entityBaseDO :【{}】 ,user :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(containerVO), JSONObject.toJSONString(partDO), JSONObject.toJSONString(entityBaseDO), JSONObject.toJSONString(user)};
        });
        this.typlmPermissionsUtil.checkCommonAddPermission(containerVO, partDO, entityBaseDO, user);
        this.setVersionInfo(containerVO, partMasterDO, partDO, partVO);
        TyplmLoggerUtil.debug(log, () -> {
            return "插入一条partMasterDO数据 ==> partMasterDO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partMasterDO)};
        });
        int insert;
        if (BooleanUtils.isTrue(partVO.getCreateMaster())) {
            insert = this.typlmPartMasterMapper.insert(partMasterDO);
            if (insert > 1) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.SYS_ERROR_SQL, new String[0]);
            }
        }

        partDO.setIopstateinteropinfo("iop_n/a");
        partDO.setStateinteropinfo("iop_c/i");
        TyplmLoggerUtil.debug(log, () -> {
            return "插入零部件跟文件夹关系数据 ==> partDO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partDO)};
        });

        PartTypeDefService partTypeDefService= SpringUtil.getBean(PartTypeDefService.class);
        if(partTypeDefService!=null){
            partTypeDefService.insertPartBefore(partDO);
        }

        this.typlmIterFolderMemberLinkService.insertIterFolderMemberLink(partDO);
        TyplmLoggerUtil.debug(log, () -> {
            return "插入零部件版本partDO ==> partDO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partDO)};
        });

        insert = this.typlmPartMapper.insert(partDO);
        if (insert > 1) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.SYS_ERROR_SQL, new String[0]);
        }

        this.setLifeCycleHistory(user, partDO, StatusActionEnum.CREATE);
        return partDO;
    }

    private void checkGenericTypeAndCollapsible(PartMasterDO partMasterDO, TyPartAndMasterDTO tyPartAndMasterDTO) {
        if (!Boolean.TRUE.equals(tyPartAndMasterDTO.getIsBatchAdd())) {
            String genericType = tyPartAndMasterDTO.getGenerictype();
            Long collapsible = tyPartAndMasterDTO.getCollapsible();
            if (StringUtils.isEmpty(genericType)) {
                throw PartBomErrorCodeEnum.GENERICTYPE_CAN_NOT_NULL.getException(new Object[0]);
            } else if (partMasterDO != null && "variant".equalsIgnoreCase(partMasterDO.getGenerictype()) && !"variant".equalsIgnoreCase(genericType)) {
                throw PartBomErrorCodeEnum.CAN_NOT_BE_UPDATED_WHEN_GENERICTYPE_IS_VARIANT.getException(new Object[0]);
            } else {
                this.checkGenericTypeDynamic(partMasterDO, tyPartAndMasterDTO);
                if ("dynamic".equalsIgnoreCase(genericType) && ObjectUtil.isNull(collapsible)) {
                    throw PartBomErrorCodeEnum.GENERICTYPE_IS_TRUE_AND_COLLAPSIBLE_NOT_NULL.getException(new Object[0]);
                } else {
                    if ("standard".equalsIgnoreCase(genericType)) {
                        collapsible = null;
                    }

                    tyPartAndMasterDTO.setGenerictype(genericType);
                    tyPartAndMasterDTO.setCollapsible(collapsible);
                }
            }
        }
    }

    private void checkGenericTypeDynamic(PartMasterDO partMasterDO, TyPartAndMasterDTO tyPartAndMasterDTO) {
        if (partMasterDO != null && "dynamic".equalsIgnoreCase(partMasterDO.getGenerictype()) && StringUtils.isNotEmpty(partMasterDO.getGenerictype()) && StringUtils.isNotEmpty(tyPartAndMasterDTO.getGenerictype()) && !partMasterDO.getGenerictype().equalsIgnoreCase(tyPartAndMasterDTO.getGenerictype())) {
            List<VariantSpecVariantLinkVO> variantSpecVariantLinkVOS = this.typlmConfiguredSuperBomService.queryPartVariantPartByDynamicPart(Lists.newArrayList(new BigInteger[]{tyPartAndMasterDTO.getOid()}));
            if (CollUtil.isNotEmpty(variantSpecVariantLinkVOS)) {
                throw PartBomErrorCodeEnum.NOT_CAN_UPDATE_GENERICTYPE_HAD_LINK_VARIANT.getException(new Object[0]);
            }

            QueryFeatureCommonConditionDTO commonConditionDTO = new QueryFeatureCommonConditionDTO();
            commonConditionDTO.setOidList(Lists.newArrayList(new BigInteger[]{tyPartAndMasterDTO.getOid()}));
            List<TyplmConfiguredVariantSpecVO> typlmConfiguredVariantSpecVOS = this.typlmConfiguredVariantSpecService.queryVariantSpecByPartList(commonConditionDTO);
            if (CollUtil.isNotEmpty(typlmConfiguredVariantSpecVOS)) {
                throw PartBomErrorCodeEnum.NOT_CAN_UPDATE_GENERICTYPE_HAD_LINK_VARIANT.getException(new Object[0]);
            }
        }

    }

    public PartDO insertPartExistMaster(TyPartAndMasterDTO partVO, UserDO user, PartMasterDO partMasterDO) {
        if (!"true".equalsIgnoreCase(partVO.getIsUpload())) {
            this.verifyParams(partVO);
        }

        ContainerVO containerVO = this.typlmContainerService.getContainerVO(partVO.getContainerType(), partVO.getContainerID(), partVO.getContainerName());
        partVO.setContainerID(containerVO.getOid());
        partVO.setContainerType(containerVO.getOtype());
        BigInteger partOid = this.snowflakeIdComponent.getInstance().nextId();
        Date newDate = new Date();
        PartDO partDO = this.packagePartVO(partVO, partMasterDO, partOid, newDate);
        TypeDO typeDO = this.setPartType(partVO, partDO);
        this.queryAndSetCreatePartLifecycle(partVO, partDO, typeDO);
        CTyEntityBaseDO entityBaseDO = this.typlmSubFolderLinkService.getCabinetOrSubFolderDO(this.convertStringToBigInteger("defaultcabinetoid", containerVO.getDefaultcabinetoid()), containerVO.getDefaultcabinetotype(), partVO.getFolderId(), partVO.getFolderPath());
        if ("true".equalsIgnoreCase(partVO.getIsUpload())) {
            this.setUploadPartContainerAndFolder(containerVO, entityBaseDO, partDO);
        } else {
            this.setPartContainerAndFolder(containerVO, entityBaseDO, partDO);
        }

        this.typlmPermissionsUtil.checkCommonAddPermission(containerVO, partDO, entityBaseDO, user);
        this.setVersionInfo(containerVO, partMasterDO, partDO, partVO);
        partDO.setIopstateinteropinfo("iop_n/a");
        partDO.setStateinteropinfo("iop_c/i");
        this.typlmIterFolderMemberLinkService.insertIterFolderMemberLink(partDO);
        int insert = this.typlmPartMapper.insert(partDO);
        if (insert > 1) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.SYS_ERROR_SQL, new String[0]);
        }

        this.setLifeCycleHistory(user, partDO, StatusActionEnum.CREATE);
        return partDO;
    }

    private void setVersionInfo(ContainerVO containerVO, PartMasterDO partMasterDO, PartDO partDO, TyPartAndMasterDTO partVO) {
        IdentifierEntity container = new IdentifierEntity(containerVO.getOtype() + ":" + containerVO.getOid());
        TySeriesOutDTO initVersion;
        if ("true".equals(partVO.getIsArchiving())) {
            TyplmLoggerUtil.debug(log, () -> {
                return "归档部件设置版本信息，查询初始化版本 ==> typeOid :【{}】,container :【{}】,partVO.getVersion() :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(partDO.getTypeoid()), JSONObject.toJSONString(container), partVO.getVersion()};
            });
            initVersion = this.typlmSeriesService.getDesignateInitVersion(partDO.getTypeoid(), container, partVO.getVersion());
            TyplmLoggerUtil.debug(log, () -> {
                return "归档部件设置版本信息，查询初始化版本结果 <== initVersion :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(initVersion)};
            });
            partMasterDO.setSeries(initVersion.getSeriesName());
            partDO.setVersion(initVersion.getVersion());
            partDO.setIterationid(partVO.getIterationid());
            partDO.setVersionsort(initVersion.getSortid());
            partDO.setCreatestamp(partVO.getCreatestamp());
            partMasterDO.setCreatestamp(partVO.getCreatestamp());
            partDO.setUpdatestamp(partVO.getModifystamp());
            partMasterDO.setUpdatestamp(partVO.getModifystamp());
            partDO.setModifystamp(partVO.getModifystamp());
            partMasterDO.setModifystamp(partVO.getModifystamp());
        } else {
            TyplmLoggerUtil.debug(log, () -> {
                return "非归档部件设置版本信息，查询初始化版本 ==> typeOid :【{}】,container :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(partDO.getTypeoid()), JSONObject.toJSONString(container)};
            });
            initVersion = this.typlmSeriesService.getInitVersion(partDO.getTypeoid(), container);
            TyplmLoggerUtil.debug(log, () -> {
                return "非归档部件设置版本信息，查询初始化版本结果 <== initVersion :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(initVersion)};
            });
            partMasterDO.setSeries(initVersion.getSeriesName());
            partDO.setVersion(initVersion.getVersion());
            partDO.setIterationid(initVersion.getIterationid());
            partDO.setVersionsort(initVersion.getSortid());
            this.typlmCompanyVersionService.initCompanyVersionInfo(partDO);
            TyplmLoggerUtil.debug(log, () -> {
                return "初始化外部版本标识后的partDO <== partDO :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(partDO)};
            });
        }

        ControlBranchDO controlBranchDO = this.typlmBranchidControlService.newBranchid(partDO);
        TyplmLoggerUtil.debug(log, () -> {
            return "插入一条branch数据 <== controlBranchDO :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(controlBranchDO)};
        });
        partDO.setBranchid(controlBranchDO.getOid());
    }

    private OrgContainerDO getPartOrgContainerDO(PartMasterDO partMasterDO) {
        OrgContainerDO orgContainerDO;
        if ("ty.inteplm.domain.CTyOrgContainer".equalsIgnoreCase(partMasterDO.getContainerotype())) {
            orgContainerDO = this.typlmOrgContainerService.queryOrgContainerByOid(partMasterDO.getContaineroid());
        } else {
            orgContainerDO = this.typlmOrgContainerService.getOrgContainerByOidOtype(partMasterDO.getContaineroid(), partMasterDO.getContainerotype());
        }

        return orgContainerDO;
    }

    public void queryAndSetCreatePartLifecycle(TyPartAndMasterDTO partVO, PartDO partDO, TypeDO typeDO) {
        if (StringUtils.isEmpty(partVO.getLifecycleTemplate())) {
            TyplmLoggerUtil.debug(log, () -> {
                return "重设生命周期模板状态 ==>  partVO :【{}】, partDO :【{}】, typeDO :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(partVO), JSONObject.toJSONString(partDO), JSONObject.toJSONString(typeDO)};
            });
            this.typlmPartEarlyService.resetLifecylceTempByBasedRule(partVO, partDO, typeDO);
        } else {
            TyplmLoggerUtil.debug(log, () -> {
                return "查询生命周期模板 ==> 生命周期模板名称 :【{}】";
            }, () -> {
                return new Object[]{partVO.getLifecycleTemplate()};
            });
            LifeCycleTemplateDO lifeCycleTemplateDO = this.typlmLifecycleTemplateService.queryLifecycleNotWrkByName(partVO.getLifecycleTemplate());
            TyplmLoggerUtil.debug(log, () -> {
                return "查询生命周期模板结果 <== lifeCycleTemplateDO :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(lifeCycleTemplateDO)};
            });
            if (!ObjectUtils.isEmpty(lifeCycleTemplateDO)) {
                partVO.setLifecycletemplateoid(lifeCycleTemplateDO.getOid());
                TyplmLoggerUtil.debug(log, () -> {
                    return "重设生命周期模板和状态 ==> partVO :【{}】, partDO :【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partVO), JSONObject.toJSONString(partDO)};
                });
                this.typlmPartEarlyService.resetLifecylceTempAndWorkFlow(partVO, partDO);
            } else {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_LIFECYCLETEMPLATE_NOT_FOUND, new String[]{partVO.getLifecycleTemplate()});
            }

        }
    }

    private void setLifeCycleHistory(UserDO user, PartDO partDO, StatusActionEnum action) {
        NewLifeCycleStateHistoryDTO newLifeCycleStateHistoryDTO = new NewLifeCycleStateHistoryDTO();
        newLifeCycleStateHistoryDTO.setState(partDO.getLifecyclestagekey());
        newLifeCycleStateHistoryDTO.setUserDO(user);
        newLifeCycleStateHistoryDTO.setBaseObject(partDO);
        newLifeCycleStateHistoryDTO.setAction(action);
        List<NewLifeCycleStateHistoryDTO> newLifeCycleStateHistoryDTOS = new ArrayList();
        newLifeCycleStateHistoryDTOS.add(newLifeCycleStateHistoryDTO);
        TyplmLoggerUtil.debug(log, () -> {
            return "插入对象的生命周期历史记录 ==> newLifeCycleStateHistoryDTOS :【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(newLifeCycleStateHistoryDTOS)};
        });
        this.typlmLifeCycleHistoryService.newLifeCycleStateHistory(newLifeCycleStateHistoryDTOS);
    }

    private void verifyParams(TyPartAndMasterDTO partVO) {
        if (StringUtils.isBlank(partVO.getContainerType())) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"containerType"});
        }

        if (StringUtils.isBlank(partVO.getContainerName())) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"containerName"});
        }

        if (StringUtils.isBlank(partVO.getFolderPath())) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"folderName"});
        }

        if (StringUtils.isEmpty(partVO.getPartMasterNumber())) {
            log.error("createPart ==>> Part Number is Null");
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"partNumber"});
        }

    }

    private void setUploadPartContainerAndFolder(ContainerVO containerVO, CTyEntityBaseDO entityBaseDO, PartDO partDO) {
        this.setContainer(containerVO, entityBaseDO, partDO);
        if (entityBaseDO instanceof SubfolderDO) {
            SubfolderDO subfolderDO = (SubfolderDO)entityBaseDO;
            if (Objects.nonNull(partDO)) {
                partDO.setSubfolderoid(subfolderDO.getOid());
                partDO.setSubfolderotype(subfolderDO.getOtype());
                partDO.setFoldernameinfo(subfolderDO.getName());
                partDO.setDomainoid(subfolderDO.getDomainoid());
                partDO.setDomainotype(subfolderDO.getDomainotype());
                partDO.setCabinetoid(subfolderDO.getCabinetoid());
                partDO.setCabinetotype(subfolderDO.getCabinetotype());
            }
        }

    }

    public void setPartContainerAndFolder(ContainerVO containerVO, CTyEntityBaseDO entityBaseDO, PartDO partDO) {
        this.setContainer(containerVO, entityBaseDO, partDO);
        if (entityBaseDO instanceof SubfolderDO) {
            SubfolderDO subfolderDO = (SubfolderDO)entityBaseDO;
            if (Objects.nonNull(partDO)) {
                if (partDO.getContaineroid().equals(subfolderDO.getContaineroid()) && partDO.getContainerotype().equals(subfolderDO.getContainerotype())) {
                    partDO.setSubfolderoid(subfolderDO.getOid());
                    partDO.setSubfolderotype(subfolderDO.getOtype());
                    partDO.setFoldernameinfo(subfolderDO.getName());
                    partDO.setDomainoid(subfolderDO.getDomainoid());
                    partDO.setDomainotype(subfolderDO.getDomainotype());
                } else {
                    TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_CONTAINER_FOLDER_NOT_FOUND, new String[]{subfolderDO.getName(), partDO.getContaineroid().toString()});
                }
            }
        }

    }

    private void setContainer(ContainerVO containerVO, CTyEntityBaseDO entityBaseDO, PartDO partDO) {
        if (Objects.nonNull(containerVO)) {
            partDO.setContaineroid(StringUtils.isNotEmpty(containerVO.getOid()) ? new BigInteger(containerVO.getOid()) : BigInteger.ZERO);
            partDO.setContainerotype(containerVO.getOtype());
            partDO.setCabinetoid(StringUtils.isNotEmpty(containerVO.getOid()) ? new BigInteger(containerVO.getDefaultcabinetoid()) : BigInteger.ZERO);
            partDO.setCabinetotype(containerVO.getDefaultcabinetotype());
            if (entityBaseDO instanceof CabinetDO) {
                partDO.setCabinetotype(containerVO.getDefaultcabinetotype());
                CabinetDO cabinetDO = (CabinetDO)entityBaseDO;
                partDO.setDomainoid(cabinetDO.getDomainoid());
                partDO.setDomainotype(cabinetDO.getDomainotype());
                partDO.setSubfolderoid(BigInteger.ZERO);
                partDO.setSubfolderotype("ty.inteplm.folder.CTySubFolder");
                partDO.setFoldernameinfo((String)null);
            }
        }

    }

    public List<PartDO> queryWrkPartByIDS(List<BigInteger> partOIDs) {
        return this.typlmPartMapper.queryWrkPartByID(partOIDs);
    }

    private PartMasterDO packagePartMasterVO(TyPartAndMasterDTO partVO, BigInteger partOid, Date newDate) {
        PartMasterDO masterDO = new PartMasterDO();
        masterDO.setOid(this.snowflakeIdComponent.getInstance().nextId());
        masterDO.setOtype("ty.inteplm.part.CTyPartMaster");
        masterDO.setPartnumber(partVO.getPartMasterNumber());
        masterDO.setName(partVO.getMasterName());
        masterDO.setMarkfordelete(PartConstant.LONG_ZERO);
        masterDO.setCreatestamp(newDate);
        masterDO.setUpdatestamp(newDate);
        masterDO.setModifystamp(newDate);
        masterDO.setDefaultunitkey(partVO.getDefaultunitkey());
        if (partVO.getDefaultunitoid() != null) {
            masterDO.setDefaultunitoid(new BigInteger(String.valueOf(partVO.getDefaultunitoid())));
        }

        masterDO.setDefaultunitotype(partVO.getDefaultunitotype());
        masterDO.setEffcalcuclationstatus(partVO.getEffcalcuclationstatus());
        masterDO.setEffpropagationstop(partVO.getEffpropagationstop());
        masterDO.setEnditem(partVO.getEnditem());
        masterDO.setGenerictype(partVO.getGenerictype());
        masterDO.setDefaulttracecode(partVO.getDefaulttracecode());
        masterDO.setSeries(partVO.getSeries());
        masterDO.setDefaultiteratedoid(partOid);
        masterDO.setDefaultiteratedotype("ty.inteplm.part.CTyPart");
        masterDO.setUpdatecount(PartConstant.LONG_ONE);
        masterDO.setHidepartinstructure(StringUtils.isEmpty(partVO.getHidePartInstructure()) ? 0L : Long.parseLong(partVO.getHidePartInstructure()));
        masterDO.setPhantom(StringUtils.isEmpty(partVO.getPhantom()) ? 0L : Long.parseLong(partVO.getPhantom()));
        masterDO.setGenerictype(partVO.getGenerictype());
        masterDO.setCollapsible(partVO.getCollapsible());
        return masterDO;
    }

    private PartDO packagePartVO(TyPartAndMasterDTO partVO, PartMasterDO partMasterDO, BigInteger partOid, Date newDate) {
        PartDO partDO = new PartDO();
        partDO.setOid(partOid);
        partDO.setOtype("ty.inteplm.part.CTyPart");
        partDO.setMasteredoid(partMasterDO.getOid());
        partDO.setMasteredotype(partMasterDO.getOtype());
        this.setPartinfo(partVO, partDO, partMasterDO);
        if (StringUtils.isNotEmpty(partVO.getVersion()) && StringUtils.isNotEmpty(partVO.getIterationid())) {
            partDO.setVersion(partVO.getVersion());
            partDO.setIterationid(partVO.getIterationid());
        } else {
            TySeriesOutDTO initVersion = this.typlmSeriesService.getInitVersion(partVO.getTypeoid(), new IdentifierEntity(partVO.getContainerType() + ":" + partVO.getContainerID()));
            partDO.setVersion(initVersion.getVersion());
            partDO.setIterationid(initVersion.getIterationid());
            partDO.setVersionsort(initVersion.getSortid());
        }

        partDO.setLastupdatestamp(newDate);
        partDO.setCreatestamp(newDate);
        partDO.setUpdatestamp(newDate);
        partDO.setModifystamp(newDate);
        partDO.setIslocked(PartConstant.LONG_ZERO);
        partDO.setLockeroid(BigInteger.ZERO);
        partDO.setUpdatecount(PartConstant.LONG_ZERO);
        partDO.setMarkfordelete(PartConstant.LONG_ZERO);
        partDO.setLockstateinfo("c/i");
        partDO.setLifecyclestagekey(partVO.getLifecyclestagekey());
        partDO.setIslastiterated(PartConstant.LONG_ONE);
        partDO.setAdhocaclisnull(PartConstant.LONG_ZERO);
        partDO.setAtgatestate(PartConstant.LONG_ZERO);
        partDO.setCheckoutinfoisnull(PartConstant.LONG_ZERO);
        partDO.setVersionlevel(PartConstant.LONG_ONE);
        partDO.setIterationstate("ctrld");
        partDO.setCheckoutinfooid(BigInteger.ZERO);
        partDO.setCheckoutinfootype("ty.inteplm.part.CTyPart");
        partDO.setViewdefotype("ty.inteplm.view.CTyViewDef");
        partDO.setParttypekey(partVO.getParttypekey() == null ? "separable" : partVO.getParttypekey());
        partDO.setName(partVO.getName());
        partDO.setSecuritylabels(partVO.getSecuritylabels());
        partDO.setVariation1(partVO.getVariation1());
        partDO.setVariation2(partVO.getVariation2());
        partDO.setLifecyclestageoid(partVO.getLifecyclestageoid());
        partDO.setLifecyclestageotype(partVO.getLifecyclestageotype());
        this.setCreator(partVO, partDO);
        return partDO;
    }

    private void setCreator(TyPartAndMasterDTO partVO, PartDO partDO) {
        UserDO userDO;
        if (StringUtils.isNotEmpty(partVO.getCreatorName())) {
            userDO = this.typlmUserService.queryUserByName(partVO.getCreatorName());
            if (Objects.isNull(userDO)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{"creator:" + partVO.getCreatorName()});
                return;
            }

            partDO.setCreatoroid(userDO.getOid());
            partDO.setCreatorotype(userDO.getOtype());
            partDO.setUpdatoroid(userDO.getOid());
            partDO.setUpdatorotype(userDO.getOtype());
        } else {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"creator"});
        }

        if ("true".equals(partVO.getIsArchiving()) && StringUtils.isNotEmpty(partVO.getModifierName())) {
            userDO = this.typlmUserService.queryUserByName(partVO.getModifierName());
            if (Objects.isNull(userDO)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_USER_NOT_FOUND, new String[]{"modifier:" + partVO.getModifierName()});
                return;
            }

            partDO.setUpdatoroid(userDO.getOid());
            partDO.setUpdatorotype(userDO.getOtype());
        }

    }

    private TypeDO setPartType(TyPartAndMasterDTO tyPartAndMasterDTO, PartDO partDO) {
        TypeDO typeDO;
        if (StringUtil.isNotEmpty(tyPartAndMasterDTO.getTypeDefName())) {
            TyplmLoggerUtil.debug(log, () -> {
                return "通过名称查询类型 ==>  类型名称 :【{}】, 对象otype ： 【{}】";
            }, () -> {
                return new Object[]{tyPartAndMasterDTO.getTypeDefName(), "ty.inteplm.part.CTyPart"};
            });
            typeDO = this.typlmTypeCommonService.getTypeDOByTypeDefName(tyPartAndMasterDTO.getTypeDefName(), "ty.inteplm.part.CTyPart");
            TyplmLoggerUtil.debug(log, () -> {
                return "通过名称查询类型 <==  typeDO :【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(typeDO)};
            });
            partDO.setTypeoid(typeDO.getOid());
            partDO.setTypeotype(typeDO.getOtype());
            return typeDO;
        } else {
            if (StringUtil.isNotEmpty(tyPartAndMasterDTO.getTypeotype())) {
                TyplmLoggerUtil.debug(log, () -> {
                    return "通过id查询类型 ==>  类型id :【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(tyPartAndMasterDTO.getTypeoid())};
                });
                typeDO = this.typlmTypeService.queryTypeByOID(tyPartAndMasterDTO.getTypeoid());
                TyplmLoggerUtil.debug(log, () -> {
                    return "通过id查询类型 <==  typeDO :【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(typeDO)};
                });
                if (ObjectUtils.isEmpty(typeDO)) {
                    TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_TYPE_DOES_NOT_EXIS_OR_UNAVAILABLE_IN_THE_SYSTEM, new String[]{String.valueOf(tyPartAndMasterDTO.getTypeoid())});
                } else {
                    if (typeDO.getMarkfordelete() == 1L) {
                        TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_TYPE_DOES_NOT_EXIS_OR_UNAVAILABLE_IN_THE_SYSTEM, new String[]{String.valueOf(tyPartAndMasterDTO.getTypeoid())});
                    }

                    partDO.setTypeoid(tyPartAndMasterDTO.getTypeoid());
                    partDO.setTypeotype(tyPartAndMasterDTO.getTypeotype());
                }
            } else {
                TyplmLoggerUtil.debug(log, () -> {
                    return "通过逻辑标识符查询类型 ==>  逻辑标识符 :【{}】";
                }, () -> {
                    return new Object[]{"ty.inteplm.part.CTyPart"};
                });
                typeDO = this.typlmTypeService.getLastTypeByLogicalidentifier("ty.inteplm.part.CTyPart");
                TyplmLoggerUtil.debug(log, () -> {
                    return "通过逻辑标识符查询类型 <==  typeDO :【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(typeDO)};
                });
                if (typeDO != null) {
                    partDO.setTypeoid(typeDO.getOid());
                    partDO.setTypeotype(typeDO.getOtype());
                } else {
                    partDO.setTypeoid(BigInteger.ZERO);
                    partDO.setTypeotype("ty.inteplm.type.CTyTypeDef");
                }
            }

            return typeDO;
        }
    }

    private void setPartRelObjectID(TyPartAndMasterDTO partAndMasterDTO, PartDO cTyPart) {
        String partView = partAndMasterDTO.getPartView();
        TyQueryMultiObjectOIDByContion tyQueryMultiObjectOIDByContion = new TyQueryMultiObjectOIDByContion();
        if (!StringUtils.isEmpty(partView)) {
            tyQueryMultiObjectOIDByContion.setModifyerName("");
            tyQueryMultiObjectOIDByContion.setOwnerName("");
            tyQueryMultiObjectOIDByContion.setViewName(StringUtils.defaultString(partView, ""));
            tyQueryMultiObjectOIDByContion.setLifecycleTemplateName("");
            List<HashMap> hashMapList = this.queryMultiObjectIDByContion(tyQueryMultiObjectOIDByContion);
            this.setPartView(cTyPart, partView, hashMapList);
        }
    }

    private void setPartView(PartDO cTyPart, String partView, List<HashMap> hashMapList) {
        if (StringUtils.isNotEmpty(partView)) {
            int result = this.getObjectOidByName(cTyPart, "viewOID", hashMapList);
            if (result <= 0) {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_OBJECT_NOT_FOUND, new String[]{"View:" + partView})));
            }
        }

    }

    public List<ConfigureBoardPartVO> searchConfigureBoardPart(String partNumber) {
        return this.typlmPartMapper.searchConfigureBoardPart(partNumber);
    }

    public PageInfo<PartAllVO> queryPagePartByCondition(PartAllQuery partAllQuery) {
        this.checkPartVersionIds(partAllQuery);
        CompletableFuture<Integer> asyncCount = this.completableFutureWrapper.supplyAsync(() -> {
            int count = this.typlmPartQueryMapper.queryPagePartCount(partAllQuery);
            if (count > 20000) {
                count = -1;
            }

            return count;
        });
        CompletableFuture<List<PartAllVO>> asyncPart = this.completableFutureWrapper.supplyAsync(() -> {
            return this.typlmPartQueryMapper.queryPagePartByCondition(partAllQuery);
        });
        if ((Integer)asyncCount.join() < 0) {
            asyncPart.cancel(true);
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_SEARCH_RESULT_EXCEED_THE_UPPER_LIMIT, new String[]{"20000"})));
        } else if ((Integer)asyncCount.join() == 0) {
            asyncPart.cancel(true);
            return new PageInfo(Collections.emptyList());
        } else {
            List<PartAllVO> partAllVOS = this.pageSetPart((List)asyncPart.join(), partAllQuery);
            PageInfo<PartAllVO> pageInfo = new PageInfo(partAllVOS);
            pageInfo.setPageNum(partAllQuery.getCurPage());
            pageInfo.setPageSize(partAllQuery.getPageSize());
            pageInfo.setTotal((long)(Integer)asyncCount.join());
            this.setPages((List)asyncPart.join(), partAllQuery, pageInfo);
            return pageInfo;
        }
    }

    private void setPages(List<PartAllVO> allPartInfo, PartAllQuery partAllQuery, PageInfo<PartAllVO> pageInfo) {
        int allRow = allPartInfo.size();
        int pagetSize = partAllQuery.getPageSize();
        if (allRow % pagetSize > 0) {
            pageInfo.setPages(allRow / pagetSize + 1);
        } else {
            pageInfo.setPages(allRow / pagetSize);
        }

    }

    private List<PartAllVO> pageSetPart(List<PartAllVO> allPartInfo, PartAllQuery partAllQuery) {
        int allRow = allPartInfo.size();
        int pagetSize = partAllQuery.getPageSize();
        int pageNum = partAllQuery.getCurPage();
        int startRow = pagetSize * (pageNum - 1);
        int endRow = startRow + pagetSize;
        if (startRow >= allRow) {
            return new ArrayList();
        } else {
            List partAllVOS;
            if (endRow > allRow) {
                partAllVOS = allPartInfo.subList(startRow, allRow);
            } else {
                partAllVOS = allPartInfo.subList(startRow, endRow);
            }

            return partAllVOS;
        }
    }

    private void checkPartVersionIds(PartAllQuery partAllQuery) {
        String partVersionId = partAllQuery.getPartVersionId();
        if (StringUtils.isNotEmpty(partVersionId)) {
            String[] splitId = partVersionId.split(",");
            String[] var4 = splitId;
            int var5 = splitId.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String versionId = var4[var6];
                if (StringUtils.isNotEmpty(versionId) && !CommonUtil.verificationIdType(versionId.trim())) {
                    partVersionId = StringUtils.replace(partVersionId, versionId, "");
                }
            }

            partAllQuery.setPartVersionId(partVersionId);
        }

    }

    public PageInfo<PartAllVO> queryPagePartLatestByCondition(PartAllQuery partAllQuery) {
        this.checkPartVersionIds(partAllQuery);
        CompletableFuture<Integer> asyncCount = this.completableFutureWrapper.supplyAsync(() -> {
            int count = this.typlmPartQueryMapper.queryPagePartLatestCont(partAllQuery);
            if (count > 20000) {
                count = -1;
            }

            return count;
        });
        CompletableFuture<List<PartAllVO>> asyncQueryPart = this.completableFutureWrapper.supplyAsync(() -> {
            return this.typlmPartQueryMapper.queryPagePartLatestByCondition(partAllQuery);
        });
        if ((Integer)asyncCount.join() < 0) {
            asyncQueryPart.cancel(true);
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_SEARCH_RESULT_EXCEED_THE_UPPER_LIMIT, new String[]{"20000"})));
        } else if ((Integer)asyncCount.join() == 0) {
            asyncQueryPart.cancel(true);
            return new PageInfo(Collections.emptyList());
        } else {
            List<PartAllVO> partAllVOS = this.pageSetPart((List)asyncQueryPart.join(), partAllQuery);
            PageInfo<PartAllVO> pageInfo = new PageInfo(partAllVOS);
            pageInfo.setPageNum(partAllQuery.getCurPage());
            pageInfo.setPageSize(partAllQuery.getPageSize());
            pageInfo.setTotal((long)(Integer)asyncCount.join());
            this.setPages((List)asyncQueryPart.join(), partAllQuery, pageInfo);
            return pageInfo;
        }
    }

    public PageInfo<PartResultDataVO> queryPart(PartDTO partDTO) {
        PageInfo<PartResultDataVO> result = null;
        if (this.esSearchSwitch) {
            result = this.typlmPartSearchService.searchPart(partDTO);
        }

        if (result != null) {
            return result;
        } else {
            this.buildQueryPartParam(partDTO);
            this.buildEscapeCharacter(partDTO);

            try {
                this.buildFolderId(partDTO);
            } catch (TyException var4) {
                return new PageInfo(new ArrayList());
            }

            this.buildSqlStatement(partDTO);
            if (this.tySwitchConfig.isOpenMysqlSwitch()) {
                List<AttributeDefVO> ibaAttrs = new ArrayList();
                if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(partDTO.getIbaAttrs())) {
                    ibaAttrs = this.verifyIbaQuery(partDTO);
                    if (CollectionUtils.isEmpty((Collection)ibaAttrs)) {
                        return new PageInfo(Collections.emptyList());
                    }
                }

                return this.queryParts(partDTO, (List)ibaAttrs);
            } else {
                return !this.verifyAndbulidIbaQuery(partDTO) ? new PageInfo(Collections.emptyList()) : this.queryParts(partDTO, new ArrayList());
            }
        }
    }

    private List<AttributeDefVO> verifyIbaQuery(PartDTO partDTO) {
        IBAQueryDTO mIBAQueryDTO = new IBAQueryDTO();
        mIBAQueryDTO.setIbaAttrs(partDTO.getIbaAttrs());
        return this.typlmIBAValueService.verifyIbaQuery(mIBAQueryDTO);
    }

    private boolean verifyAndbulidIbaQuery(PartDTO partDTO) {
        IBAQueryDTO mIBAQueryDTO = new IBAQueryDTO();
        mIBAQueryDTO.setIbaAttrs(partDTO.getIbaAttrs());
        if (this.typlmIBAValueService.verifyAndbulidIbaQuery(mIBAQueryDTO)) {
            partDTO.setIbaQueryStr(mIBAQueryDTO.getIbaQueryStr());
            return true;
        } else {
            return false;
        }
    }

    private void buildSqlStatement(PartDTO partDTO) {
        List<String> orderList = partDTO.getOrderBy();
        if (!CollectionUtils.isEmpty(orderList)) {
            List<String> stringList = (List)orderList.stream().map((strx) -> {
                return strx.toLowerCase(Locale.ROOT);
            }).distinct().collect(Collectors.toList());
            ArrayList<String> sortList = Lists.newArrayListWithCapacity(stringList.size());
            Iterator var5 = stringList.iterator();

            while(var5.hasNext()) {
                String str = (String)var5.next();
                sortList.add((String)MAP.get(str) + " " + partDTO.getSorting());
            }

            partDTO.setSortingField(StringUtils.join(sortList.toArray(), ","));
        }

    }

    private void buildQueryPartParam(PartDTO partDTO) {
        int curPage = partDTO.getCurPage();
        int pageSize = partDTO.getPageSize();
        if (StringUtil.isNotEmpty(curPage) && StringUtil.isNotEmpty(pageSize)) {
            partDTO.setCurPage(pageSize * (curPage - 1));
            partDTO.setPageSize(pageSize);
        }

        String source = partDTO.getSource();
        if (StringUtil.isNotEmpty(source)) {
            partDTO.setSource(source.toLowerCase(Locale.ROOT));
        }

        String version = partDTO.getVersion();
        if (StringUtil.isNotEmpty(version)) {
            partDTO.setVersion(version.toUpperCase(Locale.ROOT));
        }

        String defaultUnit = partDTO.getDefaultUnit();
        if (StringUtil.isNotEmpty(defaultUnit)) {
            partDTO.setDefaultUnit(defaultUnit.toUpperCase(Locale.ROOT));
        }

        String view = partDTO.getView();
        if (StringUtil.isNotEmpty(view)) {
            partDTO.setView(view.toUpperCase(Locale.ROOT));
        }

    }

    private void buildEscapeCharacter(PartDTO partDTO) {
        String partNumber = partDTO.getNumber();
        String partName;
        if (StringUtil.isNotEmpty(partNumber)) {
            partNumber = partNumber.toUpperCase(Locale.ROOT);
            if (partNumber.contains("*")) {
                partName = partNumber.replace("*", "%");
                partDTO.setNumber(partName);
            } else {
                partDTO.setNumber(partNumber);
            }
        }

        partName = partDTO.getName();
        String englishDescription;
        if (StringUtil.isNotEmpty(partName)) {
            partName = partName.toUpperCase(Locale.ROOT);
            if (partName.contains("*")) {
                englishDescription = partName.replace("*", "%");
                partDTO.setName(englishDescription);
            } else {
                partDTO.setName(partName);
            }
        }

        englishDescription = partDTO.getEnglishDescription();
        if (StringUtil.isNotEmpty(englishDescription)) {
            englishDescription = englishDescription.toUpperCase(Locale.ROOT);
            if (englishDescription.contains("*")) {
                String replace = englishDescription.replace("*", "%");
                partDTO.setEnglishDescription(replace);
            } else {
                partDTO.setEnglishDescription(englishDescription);
            }
        }

    }

    private void buildFolderId(PartDTO partDTO) {
        if (!StringUtils.isEmpty(partDTO.getFolderId())) {
            if (StringUtil.isNotEmpty(partDTO.getContainerId()) || StringUtil.isNotEmpty(partDTO.getContainerName())) {
                ContainerVO containerVO = this.typlmContainerService.getContainerVO(partDTO.getContainerType(), partDTO.getContainerId(), partDTO.getContainerName());
                partDTO.setContainerId(containerVO.getOid());
                if (StringUtil.isNotEmpty(partDTO.getFolderPath())) {
                    SubfolderDO subfolderDO = this.typlmSubFolderLinkService.getSubfolderDO(new BigInteger(containerVO.getDefaultcabinetoid()), containerVO.getDefaultcabinetotype(), (String)null, partDTO.getFolderPath());
                    partDTO.setFolderId(StringUtil.trim(subfolderDO.getOid()));
                    partDTO.setContainerId((String)null);
                }
            }

        }
    }

    private PageInfo<PartResultDataVO> queryParts(PartDTO partDTO, List<AttributeDefVO> ibaAttrs) {
        String currentDS = TyAccountContext.getDataSource();
        CompletableFuture asyncQueryPartCount;
        CompletableFuture asyncQueryPart;
        if (this.tySwitchConfig.isOpenMysqlSwitch()) {
            if (StringUtils.isEmpty(partDTO.getName()) && StringUtils.isEmpty(partDTO.getNumber())) {
                asyncQueryPartCount = this.completableFutureWrapper.supplyAsync(() -> {
                    return this.typlmPartQueryExtendMapper.queryPartCountWithNoNameAndNumber(partDTO, ibaAttrs);
                });
                asyncQueryPart = this.completableFutureWrapper.supplyAsync(() -> {
                    return this.typlmPartQueryExtendMapper.queryPartWithNoNameAndNumber(partDTO, ibaAttrs);
                });
            } else {
                asyncQueryPartCount = this.completableFutureWrapper.supplyAsync(() -> {
                    return this.typlmPartQueryExtendMapper.queryPartCount(partDTO, ibaAttrs);
                });
                asyncQueryPart = this.completableFutureWrapper.supplyAsync(() -> {
                    return this.typlmPartQueryExtendMapper.queryPart(partDTO, ibaAttrs);
                });
            }
        } else {
            asyncQueryPartCount = this.completableFutureWrapper.supplyAsync(() -> {
                TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

                Integer var3;
                try {
                    var3 = this.getCount(this.typlmPartQueryMapper.queryPartCount(partDTO));
                } finally {
                    TyDynamicDataSource.clearCurDataSource();
                }

                return var3;
            });
            asyncQueryPart = this.completableFutureWrapper.supplyAsync(() -> {
                TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

                List var3;
                try {
                    var3 = this.typlmPartQueryMapper.queryPart(partDTO);
                } finally {
                    TyDynamicDataSource.clearCurDataSource();
                }

                return var3;
            });
        }

        Integer count = (Integer)asyncQueryPartCount.join();
        if (count < 0) {
            asyncQueryPart.cancel(true);
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_SEARCH_RESULT_EXCEED_THE_UPPER_LIMIT, new String[]{"20000"})));
        } else if (count == 0) {
            asyncQueryPart.cancel(true);
            return new PageInfo(Collections.emptyList());
        } else {
            List<PartResultDataVO> resultVO = this.getPartResultDataVO((List)asyncQueryPart.join());
            PageInfo<PartResultDataVO> pageList = new PageInfo(resultVO);
            pageList.setPageSize(partDTO.getPageSize());
            pageList.setPageNum(partDTO.getCurPage());
            pageList.setTotal((long)count);
            return pageList;
        }
    }

    private List<PartResultDataVO> getPartResultDataVO(List<PartinfoVO> partInfoList) {
        if (CollectionUtils.isEmpty(partInfoList)) {
            return Collections.emptyList();
        } else {
            Map<BigInteger, String> containerNameMap = this.getContainerName(partInfoList);
            Map<BigInteger, String> folderPathMap = this.getFolderPath(partInfoList);
            List<PartResultDataVO> resultVO = new ArrayList();
            Iterator var5 = partInfoList.iterator();

            while(var5.hasNext()) {
                PartinfoVO partinfoVO = (PartinfoVO)var5.next();
                if (StringUtil.isNotEmpty(partinfoVO.getContainerId())) {
                    partinfoVO.setContainerName((String)containerNameMap.get(new BigInteger(partinfoVO.getContainerId())));
                }

                if (StringUtils.isEmpty(partinfoVO.getFolderId()) || "null".equalsIgnoreCase(partinfoVO.getFolderId())) {
                    partinfoVO.setFolderId("0");
                }

                String folderPath = (String)folderPathMap.get(new BigInteger(partinfoVO.getFolderId()));
                partinfoVO.setFolderPath(folderPath);
                PartResultDataVO partResultDataVO = new PartResultDataVO();
                partResultDataVO.setBasicAttrs(partinfoVO);
                resultVO.add(partResultDataVO);
            }

            return resultVO;
        }
    }

    private Map<BigInteger, String> getContainerName(List<PartinfoVO> partinfoList) {
        Map<String, List<PartinfoVO>> partinfoMap = (Map)partinfoList.stream().collect(Collectors.groupingBy(PartinfoVO::getContainerOtype));
        List<PartinfoVO> libraryList = (List)partinfoMap.get("ty.inteplm.library.CTyLibrary");
        List<PartinfoVO> productList = (List)partinfoMap.get("ty.inteplm.product.CTyPDMLinkProduct");
        Set<BigInteger> libraryIdSet = new HashSet();
        Set<BigInteger> productIdSet = new HashSet();
        if (!CollectionUtils.isEmpty(libraryList)) {
            libraryIdSet = (Set)libraryList.stream().map((xy) -> {
                return new BigInteger(xy.getContainerId());
            }).collect(Collectors.toSet());
        }

        if (!CollectionUtils.isEmpty(productList)) {
            productIdSet = (Set)productList.stream().map((xy) -> {
                return new BigInteger(xy.getContainerId());
            }).collect(Collectors.toSet());
        }

        List<BigInteger> libraryIds = new ArrayList((Collection)libraryIdSet);
        List<BigInteger> productIdS = new ArrayList((Collection)productIdSet);
        Map<BigInteger, String> containerNameMap = this.typlmContainerService.getContainerNameByList(libraryIds, "ty.inteplm.library.CTyLibrary");
        if (Objects.isNull(containerNameMap)) {
            containerNameMap = new HashMap();
        }

        ((Map)containerNameMap).putAll(this.typlmContainerService.getContainerNameByList(productIdS, "ty.inteplm.product.CTyPDMLinkProduct"));
        return (Map)containerNameMap;
    }

    private Map<BigInteger, String> getFolderPath(List<PartinfoVO> partInfoList) {
        Set<BigInteger> folderIdSet = new HashSet();

        PartinfoVO partInfoVO;
        for(Iterator var3 = partInfoList.iterator(); var3.hasNext(); folderIdSet.add(new BigInteger(StringUtil.getDefaultStringValue(partInfoVO.getFolderId(), "0")))) {
            partInfoVO = (PartinfoVO)var3.next();
            String checkoutState = partInfoVO.getCheckoutState();
            if (checkoutState.equals("wrk")) {
                PartDO partDO = this.queryPartByOid(partInfoVO.getSourceIterationOid(), (String)null);
                partInfoVO.setFolderId(String.valueOf(partDO.getSubfolderoid()));
            }
        }

        return this.typlmSubFolderLinkService.recursiveQueryFolderPathByIdList(new ArrayList(folderIdSet));
    }

    public TyPartAllVO queryPartAllVO(BigInteger oid, String otype) {
        TyPartAllVO partAllVO = new TyPartAllVO();
        if (!Objects.isNull(oid) && ObjectUtil.compare(BigInteger.ZERO, oid, false) != 0) {
            PagePartQuery pagePartQuery = new PagePartQuery();
            pagePartQuery.setOid(oid);
            List<TyPartAllVO> partAllVOS = this.typlmPartMapper.queryPartByCondition(pagePartQuery);
            if (!CollectionUtils.isEmpty(partAllVOS)) {
                partAllVO = (TyPartAllVO)partAllVOS.get(0);
            }

            return partAllVO;
        } else {
            return partAllVO;
        }
    }

    public List<TyPartAllVO> queryPartAllVOList(List<BigInteger> partIdList) {
        if (!CollUtil.isNotEmpty(partIdList)) {
            return Collections.emptyList();
        } else {
            List<TyPartAllVO> result = new ArrayList();
            List<List<BigInteger>> split = CollUtil.split(CollUtil.distinct(partIdList), 800);
            Iterator var4 = split.iterator();

            while(var4.hasNext()) {
                List<BigInteger> list = (List)var4.next();
                result.addAll(this.typlmPartMapper.queryPartAllVOByIdList(list));
            }

            this.partBomUtils.buildBomDisplayNameList(result);
            return result;
        }
    }

    private BigInteger convertStringToBigInteger(String param, String value) {
        BigInteger bigInteger = null;
        if (value == null) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{param});
        }

        try {
            bigInteger = new BigInteger(value);
        } catch (NumberFormatException var5) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_FORMAT_ERROR, new String[]{param, value});
        }

        return bigInteger;
    }

    public List<MyCheckoutObjVO> queryPartCheckoutByMyself(BigInteger userOid) {
        return this.typlmPartQueryMapper.queryPartCheckoutByMyself(userOid);
    }

    public List<MyCheckoutObjVO> queryPartCheckoutByMyselfNew(BigInteger userOid) {
        return this.typlmPartQueryMapper.queryPartCheckoutByMyselfNew(userOid);
    }

    public int batchUpdateLifecyclestagekey(List<PartDO> partList) {
        return this.typlmPartMapper.batchUpdateLifecyclestagekey(partList);
    }

    public PartDO selectByPrimaryKey(BigInteger primaryKey) {
        return (PartDO)this.typlmPartMapper.selectByPrimaryKey(primaryKey);
    }

    public List<PartbasicAttrsVO> getPartBasicAttrs(List<BigInteger> partMasterIds) {
        String language = (String)CommonConstant.GET_LOCALE_PROPERTY_VALUE_LANGUAGE.get(TyCommonExtUtil.getFrontLanguage());
        return this.typlmPartMapper.getPartBasicAttrs(partMasterIds, TyAccountContext.getUser().getOid(), language);
    }

    public List<PartDO> checkDocByWrkIds(List<BigInteger> ids) {
        return this.typlmPartMapper.checkDocByWrkIds(ids);
    }

    public List<PartDO> getPartDOListByMasteredOids(List<BigInteger> masteredOids, String islastiterated) {
        Example example = new Example(PartDO.class, true, true);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("masteredoid", masteredOids);
        if (StringUtils.isNotBlank(islastiterated)) {
            criteria.andEqualTo("islastiterated", CommonUtil.stringToBigIntegers(islastiterated));
        }

        return this.typlmPartMapper.selectByExample(example);
    }

    public String getValueFromMap(Map<String, List<Map>> hashMaps, String oid, String attrName) {
        List<Map> list = (List)hashMaps.get(oid);
        if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(list)) {
            Iterator var5 = list.iterator();

            while(var5.hasNext()) {
                Map m = (Map)var5.next();
                String atrributeName = Optional.ofNullable(m.get("ATTRIBUTENAME")).orElse("").toString();
                String attributeValue = Optional.ofNullable(m.get("ATTRIBUTEVALUE")).orElse("").toString();
                if (attrName.equalsIgnoreCase(atrributeName)) {
                    return attributeValue;
                }
            }
        }

        return "";
    }

    public void batchUpdateLifecycleManagedKey(List updateObjectLifecycleList) {
        this.typlmCommonLifecycleService.checkObjectStatus(updateObjectLifecycleList);
        this.typlmPartMapper.batchUpdateLifecyclestagekey(updateObjectLifecycleList);
    }

    public List<CTyEntityBaseDO> getItemsByIDList(List<BigInteger> idList) {
        Example example = new Example(PartDO.class, true, true);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIn("oid", idList);
        List<PartDO> partDOList = this.typlmPartMapper.selectByExample(example);
        return ConvertUtils.castList(partDOList, CTyEntityBaseDO.class);
    }

    public PartDO updatePartAndMaster(PartDO sourcePart, TyPartAndMasterDTO partAndMasterDTO, boolean isAsynchronous) {
        UserDO userDO = TyAccountContext.getUser();
        BigInteger loginUserId = userDO.getOid();
        if (!isAsynchronous && !this.typlmPermissionsUtil.checkPermissions(sourcePart, "修改", loginUserId)) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_RIGHT_NO_MODIFY, new String[]{CommonUtil.getEntityDisplayName(sourcePart)});
        }

        this.validSourcePart(sourcePart);
        PartDO newPart = new PartDO();
        BeanCopier beanCopier = BeanCopier.create(PartDO.class, PartDO.class, false);
        beanCopier.copy(sourcePart, newPart, (Converter)null);
        this.updateSourcePart(sourcePart);
        if (isAsynchronous) {
            if (null == partAndMasterDTO.getOwnerName()) {
                newPart.setOwnerotype("ty.inteplm.org.CTyUser");
            } else if (partAndMasterDTO.getOwnerName().length() == 0) {
                newPart.setOwneroid((BigInteger)null);
            } else {
                newPart.setOwnerotype("ty.inteplm.org.CTyUser");
            }
        }

        this.insertNewPart(newPart, sourcePart, partAndMasterDTO, loginUserId.toString());
        this.checkAndMovePart(sourcePart, partAndMasterDTO);
        this.typlmIteratorUtilService.copyDynamicAccess(sourcePart, newPart);
        this.typlmPartIteratorService.copyAttr(sourcePart, newPart, loginUserId);
        return newPart;
    }

    private void checkAndMovePart(PartDO sourcePart, TyPartAndMasterDTO partAndMasterDTO) {
        String containerName = partAndMasterDTO.getContainerName();
        String containerType = partAndMasterDTO.getContainerType();
        String folderName = partAndMasterDTO.getFolderPath();
        boolean containerFlag = StringUtils.isNotEmpty(containerType) && StringUtils.isNotEmpty(containerName) && StringUtils.isNotEmpty(folderName);
        if (containerFlag) {
            ContainerVO containerVO = this.typlmContainerService.getContainerVOByName(containerType, containerName);
            CTyEntityBaseDO entityBaseDO = this.typlmSubFolderLinkService.getCabinetOrSubFolderDO(CommonUtil.stringToBigIntegers(containerVO.getDefaultcabinetoid()), containerVO.getDefaultcabinetotype(), (String)null, folderName);
            MoveObjectParamsDTO moveObjectParamsDTO = new MoveObjectParamsDTO();
            moveObjectParamsDTO.setId(sourcePart.getOid().toString());
            moveObjectParamsDTO.setTypeDefName(sourcePart.getOtype());
            if (entityBaseDO instanceof CabinetDO) {
                CabinetDO cabinetDO = (CabinetDO)entityBaseDO;
                moveObjectParamsDTO.setCabinetOid(cabinetDO.getOid().toString());
                moveObjectParamsDTO.setFolderId("0");
            }

            if (entityBaseDO instanceof SubfolderDO) {
                SubfolderDO subfolderDO = (SubfolderDO)entityBaseDO;
                moveObjectParamsDTO.setFolderId(subfolderDO.getOid().toString());
            }

            if (sourcePart.getContaineroid().toString().equals(containerVO.getOid())) {
                this.typlmFolderService.moveByFolder(moveObjectParamsDTO, "N");
            } else {
                this.typlmFolderService.moveByFolder(moveObjectParamsDTO, "Y");
            }

        }
    }

    private void updateSourcePart(PartDO sourcePart) {
        Date date = new Date();
        sourcePart.setIslocked(0L);
        sourcePart.setLockdate(date);
        sourcePart.setLockeroid(BigInteger.ZERO);
        sourcePart.setLockstate(0L);
        sourcePart.setUpdatestamp(date);
        sourcePart.setIslastiterated(0L);
        this.typlmPartMapper.updateByPrimaryKeySelective(sourcePart);
    }

    private void insertNewPart(PartDO newPart, PartDO sourcePart, TyPartAndMasterDTO partAndMasterDTO, String loginUserId) {
        Date date = new Date();
        newPart.setOid(this.typlmIteratorUtilService.getPrim());
        newPart.setIslocked(0L);
        newPart.setLockdate(date);
        newPart.setLockstate(0L);
        newPart.setLockeroid(BigInteger.ZERO);
        newPart.setLockstateinfo("c/i");
        newPart.setUpdatestamp(date);
        newPart.setModifystamp(date);
        newPart.setLastupdatestamp(date);
        newPart.setSourceiterationoid(sourcePart.getOid());
        newPart.setSourceiterationotype(sourcePart.getOtype());
        newPart.setIslastiterated(1L);
        newPart.setIterationid(String.valueOf(Integer.parseInt(sourcePart.getIterationid()) + 1));
        newPart.setUpdatecount(newPart.getUpdatecount() + 1L);
        if (StringUtil.isNotEmpty(partAndMasterDTO.getDefaultunitkey())) {
            this.verifyUnit(partAndMasterDTO.getDefaultunitkey());
        }

        this.setModifyer(partAndMasterDTO, newPart, loginUserId);
        PartMasterDO partMasterDO = this.queryPartMasterDOByOID(newPart.getMasteredoid());
        PartMasterDO partMasterDOTemp = new PartMasterDO();
        BeanCopier beanCopier = BeanCopier.create(PartMasterDO.class, PartMasterDO.class, false);
        beanCopier.copy(partMasterDO, partMasterDOTemp, (Converter)null);
        this.setPartAndPartMasterInfo(partAndMasterDTO, newPart, partMasterDO);
        if (!partMasterDO.equals(partMasterDOTemp)) {
            this.updatePartMaster(partMasterDO);
        }

        this.typlmPartMapper.insert(newPart);
        if (sourcePart.getLifecycletemplateoid().compareTo(newPart.getLifecycletemplateoid()) != 0) {
            NewLifeCycleStateHistoryDTO historyDTO = new NewLifeCycleStateHistoryDTO();
            historyDTO.setAction(StatusActionEnum.SETSTATE);
            historyDTO.setBaseObject(newPart);
            historyDTO.setLifecyclestagekey(sourcePart.getLifecyclestagekey());
            historyDTO.setState(newPart.getLifecyclestagekey());
            historyDTO.setUserDO(CommonUtil.getUser());
            this.typlmLifeCycleHistoryService.newLifeCycleStateHistory(Collections.singletonList(historyDTO));
        }

    }

    private void setPartAndPartMasterInfo(TyPartAndMasterDTO partAndMasterDTO, PartDO newPart, PartMasterDO partMasterDO) {
        this.setOwner(partAndMasterDTO, newPart);
        partMasterDO.setDefaultunitkey(StringUtil.defaultString(partAndMasterDTO.getDefaultunitkey(), partMasterDO.getDefaultunitkey()));
        partMasterDO.setName(StringUtil.defaultString(partAndMasterDTO.getMasterName(), partMasterDO.getName()));
        partMasterDO.setGenerictype(StringUtil.defaultString(partAndMasterDTO.getGenerictype(), partMasterDO.getGenerictype()));
        if (StringUtils.isNotEmpty(partAndMasterDTO.getHidePartInstructure())) {
            partMasterDO.setHidepartinstructure(Long.parseLong(partAndMasterDTO.getHidePartInstructure()));
        }

        newPart.setParttypekey(StringUtil.defaultString(partAndMasterDTO.getParttypekey(), newPart.getParttypekey()));
        newPart.setEnglishdescription(StringUtil.defaultString(partAndMasterDTO.getEnglishdescription(), newPart.getEnglishdescription()));
        newPart.setOrgcode(StringUtil.defaultString(partAndMasterDTO.getOrgcode(), newPart.getOrgcode()));
        newPart.setSourcekey(StringUtil.defaultString(partAndMasterDTO.getSourcekey(), newPart.getSourcekey()));
        newPart.setIterationnote(StringUtil.defaultString(partAndMasterDTO.getIterationnote(), ""));
        if (CommonUtil.isBigIntegerZeroOrNull(partAndMasterDTO.getTypeid())) {
            newPart.setTypeid(partAndMasterDTO.getTypeid());
        }

        if (CommonUtil.isLongZeroOrNull(partAndMasterDTO.getResourcecategroyid())) {
            newPart.setResourcecategroyid(partAndMasterDTO.getResourcecategroyid());
        }

        this.setIteratedName(partAndMasterDTO, newPart);
        this.setLifecycleTemplateName(partAndMasterDTO, newPart);
    }

    private void setIteratedName(TyPartAndMasterDTO partAndMasterDTO, PartDO newPart) {
        if (null != partAndMasterDTO.getIteratedName()) {
            if (StringUtils.isNotBlank(partAndMasterDTO.getIteratedName())) {
                newPart.setName(partAndMasterDTO.getIteratedName());
            } else {
                newPart.setName("");
            }

        }
    }

    private void setLifecycleTemplateName(TyPartAndMasterDTO partAndMasterDTO, PartDO newPart) {
        String lifecycleTemplateName = partAndMasterDTO.getLifecycleTemplate();
        if (StringUtils.isNotEmpty(lifecycleTemplateName)) {
            LifeCycleTemplateDO lifeCycleTemplateDO = this.typlmLifecycleTemplateService.queryLifecycleNotWrkByName(lifecycleTemplateName);
            if (Objects.isNull(lifeCycleTemplateDO)) {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_LIFECYCLETEMPLATE_NOT_FOUND, new String[]{lifecycleTemplateName})));
            }

            partAndMasterDTO.setLifecycletemplateoid(lifeCycleTemplateDO.getOid());
            this.typlmPartEarlyService.resetLifecylceTempAndWorkFlow(partAndMasterDTO, newPart);
        }

    }

    private void validSourcePart(PartDO sourcePart) {
        Long latest = sourcePart.getIslastiterated();
        if (latest == null || latest != 1L) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_OBJECT_NOT_LATEST_ERROR, new String[]{CommonUtil.getEntityDisplayName(sourcePart)});
        }

        String lockStateInfo = sourcePart.getLockstateinfo();
        if (!"c/i".equals(lockStateInfo)) {
            String lockerOid = this.typlmIteratorUtilService.getUserNameById(sourcePart.getLockeroid());
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_OBJECT_HAVE_CHECKED_OUT, new String[]{CommonUtil.getEntityDisplayName(sourcePart), lockerOid});
        }

    }

    public List<LatestPartVersionVO> batchGetLatestPartVersionID(List<BigInteger> listOid, BigInteger userOid) {
        return this.typlmPartMapper.batchGetLatestPartVersionID(listOid, userOid);
    }

    public List<PartMasterDO> getPartMasterDOS(List<String> partNumberList) {
        long begin = System.currentTimeMillis();
        List<PartMasterDO> partMasterDOList = new ArrayList();
        List nonExistentNumber;
        if (!CollectionUtils.isEmpty(partNumberList)) {
            nonExistentNumber = CommonUtil.subObjectList(partNumberList, 999);
            Iterator var6 = nonExistentNumber.iterator();

            while(var6.hasNext()) {
                List<String> listPartNumber = (List)var6.next();
                partMasterDOList.addAll(this.queryPartMasterList(listPartNumber));
            }
        }

        nonExistentNumber = this.getUnExistPartNumber(partNumberList, partMasterDOList);
        if (!CollectionUtils.isEmpty(nonExistentNumber)) {
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_PART_NOT_FOUND, new String[]{StringUtils.join(nonExistentNumber, ",")})));
        } else {
            log.info("getPartMasterDOS end time：-------" + (System.currentTimeMillis() - begin) + "ms");
            return partMasterDOList;
        }
    }

    private List<String> getUnExistPartNumber(List<String> partNumberList, List<PartMasterDO> partMasterDOList) {
        Map<String, String> dataMap = new HashMap();
        Iterator var4 = partMasterDOList.iterator();

        while(var4.hasNext()) {
            PartMasterDO partMasterDO = (PartMasterDO)var4.next();
            dataMap.put(partMasterDO.getPartnumber(), partMasterDO.getPartnumber());
        }

        List<String> unExistNumber = CommonUtil.getUnExistObjList(dataMap, partNumberList);
        return unExistNumber;
    }

    public PartDO queryModifiedPart(BigInteger partOid) {
        PartDO partDO = this.selectByPrimaryKey(partOid);
        if (partDO == null) {
            TyException.throwSingleTyExceptionArray(ResponseCodeEnum.BIZ_OBJECT_NOT_FOUND, new String[]{String.valueOf(partOid)});
        } else {
            if (!"wrk".equals(partDO.getLockstateinfo())) {
                TyException.throwSingleTyExceptionArray(ResponseCodeEnum.BIZ_OBJECT_NOT_WORKING_COPY_CANNOT_MODIFIED, new String[]{String.valueOf(partDO.getOid())});
            }

            BigInteger userOid = TyAccountContext.getUser().getOid();
            if (!this.typlmPermissionsUtil.checkPermissions(partDO, "修改", userOid)) {
                TyException.throwSingleTyExceptionArray(ResponseCodeEnum.BIZ_RIGHT_NO_MODIFY, new String[]{String.valueOf(partDO.getOid())});
            }
        }

        return partDO;
    }

    public PartInfoVO queryPartByMultiTypeAndContext(QueryPartByMultiTypeAndContextDTO queryPartByMultiTypeAndContextDTO) {
        QueryPartByMultiTypeAndContextParamsDTO params = queryPartByMultiTypeAndContextDTO.getParams();
        this.buildParams(params);
        PageInfoDTO pageInfo = queryPartByMultiTypeAndContextDTO.getPageInfo();
        if (pageInfo == null) {
            pageInfo = new PageInfoDTO(1, 30, 0);
        }

        if (pageInfo.getPageSize() > 100) {
            pageInfo.setPageSize(30);
        }

        int pageSize = pageInfo.getPageSize();
        int startSize = (pageInfo.getCurPage() - 1) * pageSize;
        pageInfo.setStartSize(startSize);
        List<SortInfoDTO> sortInfo = queryPartByMultiTypeAndContextDTO.getSortInfo();
        if (!CollectionUtils.isEmpty(sortInfo)) {
            Iterator var7 = sortInfo.iterator();

            while(var7.hasNext()) {
                SortInfoDTO info = (SortInfoDTO)var7.next();
                if (!"number".equals(info.getOrderBy()) && !"modifyTime".equals(info.getOrderBy()) && !"createTime".equals(info.getOrderBy()) && !"name".equals(info.getOrderBy())) {
                    sortInfo = null;
                    break;
                }
            }
        }

        UserDO userDO = TyAccountContext.getUser();
        BigInteger userId = userDO.getOid();
        String viewdefname = queryPartByMultiTypeAndContextDTO.getParams().getViewdefname();
        List<BigInteger> parentViewOidList = this.typlmViewDefService.queryParentViewIdsByName(viewdefname);
        params.setViewdefname("");
        List<PartInfoBasicAttrsVO> partInfoBasicAttrsVOS = this.typlmPartQueryMapper.queryPartByMultiTypeAndContext(params, userId, pageInfo, sortInfo, parentViewOidList);
        int totalRows = this.typlmPartQueryMapper.queryTotalRowsByMultiTypeAndContext(params, userId, parentViewOidList);
        PageInfoVO pageInfoVO = new PageInfoVO(totalRows, pageInfo.getCurPage(), pageSize);
        List<String> codeList = (List)partInfoBasicAttrsVOS.stream().map((item) -> {
            return item.getLifecycleState().getCode();
        }).collect(Collectors.toList());
        Map<String, String> codeMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(codeList, "LifeCycleState", TyCommonExtUtil.getFrontLanguage());
        partInfoBasicAttrsVOS.forEach((item) -> {
            item.getLifecycleState().setName((String)codeMap.get(item.getLifecycleState().getCode()));
        });
        PartInfoVO partInfoVO = new PartInfoVO(partInfoBasicAttrsVOS, pageInfoVO);
        return partInfoVO;
    }

    public List<PartLinkDocVO> getPartLinkDocByIds(QueryPartDocDTO queryPartDocDTO) {
        List<PartLinkDocDTO> params = queryPartDocDTO.getParams();
        Iterator var3 = params.iterator();

        while(var3.hasNext()) {
            PartLinkDocDTO partLinkDocDTO = (PartLinkDocDTO)var3.next();
            CommonUtil.stringToBigIntegers(partLinkDocDTO.getId());
        }

        List<String> referenceDocPartIds = new ArrayList();
        List<String> descriptionDocPartIds = new ArrayList();
        Iterator var5 = params.iterator();

        while(var5.hasNext()) {
            PartLinkDocDTO partLinkDocDTO = (PartLinkDocDTO)var5.next();
            if ("reference".equalsIgnoreCase(partLinkDocDTO.getAssociationType())) {
                referenceDocPartIds.add(partLinkDocDTO.getId());
            }

            if ("description".equalsIgnoreCase(partLinkDocDTO.getAssociationType())) {
                descriptionDocPartIds.add(partLinkDocDTO.getId());
            }

            if (StringUtils.isEmpty(partLinkDocDTO.getAssociationType())) {
                referenceDocPartIds.add(partLinkDocDTO.getId());
                descriptionDocPartIds.add(partLinkDocDTO.getId());
            }
        }

        UserDO user = TyAccountContext.getUser();
        List<PartLinkDocVO> partLinkDocVOS = this.typlmPartQueryMapper.getPartLinkDocByIds(user.getOid(), referenceDocPartIds, descriptionDocPartIds);
        List<String> codeList = (List)partLinkDocVOS.stream().map((item) -> {
            return item.getBasicAttrs().getLifecycleStateCode();
        }).collect(Collectors.toList());
        Map<String, String> codeMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(codeList, "LifeCycleState", TyCommonExtUtil.getFrontLanguage());
        partLinkDocVOS.forEach((item) -> {
            item.getBasicAttrs().setLifecycleStateName((String)codeMap.get(item.getBasicAttrs().getLifecycleStateCode()));
        });
        return partLinkDocVOS;
    }

    private void buildParams(QueryPartByMultiTypeAndContextParamsDTO params) {
        params.setKeywords(this.getFuzzyCondition(params.getKeywords()));
        params.setName(this.getFuzzyCondition(params.getName()));
        params.setNumber(this.getFuzzyCondition(params.getNumber()));
        params.setDescription(this.getFuzzyCondition(params.getDescription()));
        params.setEnglishDescription(this.getFuzzyCondition(params.getEnglishDescription()));
        String queryRange = params.getQueryRange();
        if (StringUtils.isEmpty(queryRange)) {
            queryRange = "LATEST";
        }

        queryRange = queryRange.toUpperCase(Locale.ROOT);
        params.setQueryRange(queryRange);
    }

    private String getFuzzyCondition(String condition) {
        return StringUtils.isNotEmpty(condition) ? condition.replace("*", "%") : "";
    }

    public List<TyPartAllVO> queryPartLatestByMasterIds(List<BigInteger> masterOids) {
        return (List)(CollectionUtils.isEmpty(masterOids) ? new ArrayList() : this.typlmPartMapper.queryPartLatestByMasterIds(masterOids, CommonUtil.getUser().getOid()));
    }

    public List<PartMasterDO> queryPartMasterByMasterIds(List<BigInteger> masterOids) {
        List<PartMasterDO> result = new ArrayList();
        List<List<BigInteger>> split = CollUtil.split(CollUtil.distinct(masterOids), 800);
        Iterator var4 = split.iterator();

        while(var4.hasNext()) {
            List<BigInteger> list = (List)var4.next();
            Example ex = this.getExample(list);
            result.addAll(this.typlmPartMasterMapper.selectByExample(ex));
        }

        return result;
    }

    public List<PartDetailResponseVO> batchQueryPartDetailByids(PartDetailDTO partDetailDTO) {
        List<ParamIdDTO> paramIdDTOList = partDetailDTO.getQueryConditions();
        if (CollectionUtils.isEmpty(paramIdDTOList)) {
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"ID"})));
        } else {
            List<PartDetailResponseVO> responseVOS = new ArrayList();
            UserDO user = TyAccountContext.getUser();
            if (Objects.isNull(user)) {
                throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_PARTICIPANTS_NOT_FOUND)));
            } else {
                List<BigInteger> hasPermissionOids = this.getHasPremissionOid(paramIdDTOList, user);
                if (CollectionUtils.isEmpty(hasPermissionOids)) {
                    return responseVOS;
                } else {
                    PartDetailAttrsDTO returnAttrsDTO = partDetailDTO.getReturnAttrs();
                    List<PartDetailResponseVO> responseVOS1 = this.getPartDetailResponseByOids(user, hasPermissionOids, returnAttrsDTO);
                    return responseVOS1;
                }
            }
        }
    }

    private List<PartDetailResponseVO> getPartDetailResponseByOids(UserDO user, List<BigInteger> hasPermissionOids, PartDetailAttrsDTO returnAttrsDTO) {
        String currentDS = TyAccountContext.getDataSource();
        List<PartDetailVO> partDetailVOS = this.batchQueryPartBasicAttrs(hasPermissionOids, user);
        CompletableFuture<Boolean> asyncSetFloder = this.completableFutureWrapper.supplyAsync(() -> {
            TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

            Boolean var3;
            try {
                this.setFolderPath(partDetailVOS);
                var3 = true;
            } finally {
                TyDynamicDataSource.clearCurDataSource();
            }

            return var3;
        });
        CompletableFuture<Map<String, List<AttributeVO>>> asyncQueryPartIBA = this.completableFutureWrapper.supplyAsync(() -> {
            TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

            Map var4;
            try {
                var4 = this.queryPartIBA(returnAttrsDTO, hasPermissionOids);
            } finally {
                TyDynamicDataSource.clearCurDataSource();
            }

            return var4;
        });
        CompletableFuture<Map<String, List<AttributeVO>>> asyncQueryMasterIBA = this.completableFutureWrapper.supplyAsync(() -> {
            TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

            Map var4;
            try {
                var4 = this.queryPartMasterIBA(returnAttrsDTO, partDetailVOS);
            } finally {
                TyDynamicDataSource.clearCurDataSource();
            }

            return var4;
        });
        CompletableFuture<Map<BigInteger, List<ComplexAttrsVO>>> asyncComplexMap = this.completableFutureWrapper.supplyAsync(() -> {
            TySwitchConfig.setCurDataSource(this.tySwitchConfig, currentDS);

            Map var4;
            try {
                var4 = this.getComplexAttrs(hasPermissionOids, returnAttrsDTO);
            } finally {
                TyDynamicDataSource.clearCurDataSource();
            }

            return var4;
        });
        List<PartDetailResponseVO> responseVOS = new ArrayList();
        if (CollectionUtils.isEmpty(partDetailVOS)) {
            asyncSetFloder.cancel(true);
            asyncQueryPartIBA.cancel(true);
            asyncQueryMasterIBA.cancel(true);
            asyncComplexMap.cancel(true);
            return responseVOS;
        } else {
            asyncSetFloder.join();
            List<PartDetailResponseVO> responseVOS1 = this.buildPartDetailResponse(partDetailVOS, (Map)asyncQueryPartIBA.join(), (Map)asyncQueryMasterIBA.join(), (Map)asyncComplexMap.join());
            return responseVOS1;
        }
    }

    private Map<BigInteger, List<ComplexAttrsVO>> getComplexAttrs(List<BigInteger> hasPermissionOids, PartDetailAttrsDTO returnAttrsDTO) {
        Map<BigInteger, List<ComplexAttrsVO>> complexAttrsMap = new HashMap();
        if ("Y".equalsIgnoreCase(returnAttrsDTO.getIsReturnAllComplexAttrs())) {
            complexAttrsMap = this.typlmExtDataValueQueryService.queryExtByIdList(hasPermissionOids, new ArrayList());
        }

        if ("N".equalsIgnoreCase(returnAttrsDTO.getIsReturnAllComplexAttrs()) && !CollectionUtils.isEmpty(returnAttrsDTO.getComplexAttrs())) {
            complexAttrsMap = this.typlmExtDataValueQueryService.queryExtByIdList(hasPermissionOids, returnAttrsDTO.getComplexAttrs());
        }

        return (Map)complexAttrsMap;
    }

    public List<PartDetailResponseVO> batchQueryPartDetailByNumbers(PartDetailByNumberDTO partDetailDTO) {
        UserDO user = TyAccountContext.getUser();
        if (Objects.isNull(user)) {
            throw new TyException(Collections.singletonList(new TyException(ResponseCodeEnum.BIZ_PARTICIPANTS_NOT_FOUND)));
        } else {
            List<TyPartAllVO> tyPartAllVOS = this.typlmPartQueryMapper.batchQueryLatestPartByNumber(partDetailDTO.getQueryConditions(), user.getOid());
            List<PartDetailResponseVO> partDetailResponseVOS = new ArrayList();
            if (!CollectionUtils.isEmpty(tyPartAllVOS)) {
                List<String> permissionList = new ArrayList();

                for(int i = 0; i < tyPartAllVOS.size(); ++i) {
                    permissionList.add("读取");
                }

                List<String> noPermissionOids = this.typlmPermissionsUtil.getNoPermissionOids(user, new ArrayList(tyPartAllVOS), permissionList);
                List<BigInteger> partOids = new ArrayList();
                tyPartAllVOS.stream().filter((partVO) -> {
                    return !noPermissionOids.contains(partVO.getOid().toString());
                }).forEach((tyPartAllVO) -> {
                    partOids.add(tyPartAllVO.getOid());
                });
                if (!CollectionUtils.isEmpty(partOids)) {
                    partDetailResponseVOS = this.getPartDetailResponseByOids(user, partOids, partDetailDTO.getReturnAttrs());
                }
            }

            return (List)partDetailResponseVOS;
        }
    }

    @Transactional(
            rollbackFor = {Exception.class}
    )
    public void batchInsert(List<PartDO> list) {
        if (!CollectionUtils.isEmpty(list)) {
            int num = (int)Math.ceil((double)list.size() / 300.0);
            if (list.size() > 300) {
                for(int i = 1; i <= num; ++i) {
                    if (i == num) {
                        this.typlmPartMapper.batchInsert(list.subList((i - 1) * 300, list.size()));
                    } else {
                        this.typlmPartMapper.batchInsert(list.subList((i - 1) * 300, i * 300));
                    }
                }
            } else {
                this.typlmPartMapper.batchInsert(list);
            }

        }
    }

    private Map<String, Long> buildPermissionMap(List<TyPartAllVO> tyPartAllVOs) {
        List<CTyEntityBaseDO> entityList = new ArrayList();
        List<PrincipalEntity> principalList = new ArrayList();
        UserDO user = TyAccountContext.getUser();
        Iterator var6 = tyPartAllVOs.iterator();

        while(var6.hasNext()) {
            TyPartAllVO entry = (TyPartAllVO)var6.next();
            entityList.add(new CTyEntityBaseDO(entry.getOid(), entry.getOtype()));
            principalList.add(new PrincipalEntity(user.getOid(), user.getOtype()));
        }

        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询权限 ==> entityList : 【{}】, principalList : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(entityList), JSONObject.toJSONString(principalList)};
        });
        Map<String, Long> premissionMap = this.pdmAccessJudgeService.getChangedPdmObjectRightList(new ArrayList(entityList), principalList);
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询权限 <== premissionMap : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(premissionMap)};
        });
        return premissionMap;
    }

    public PartDetailsVO queryPartDetails(BigInteger oid, String oType) {
        PartDetailsVO partDetailsVO = new PartDetailsVO();
        if (ObjectUtils.isEmpty(oid)) {
            return null;
        } else {
            TyplmLoggerUtil.debug(log, () -> {
                return "零部件详情 通过oid otype查询tyPartAllVO ==> oid : 【{}】, oType : 【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(oid), oType};
            });
            TyplmLoggerUtil.performanceStart();
            TyPartAllVO tyPartAllVO = this.typlmPartService.queryPartAllVO(oid, oType);
            TyplmLoggerUtil.performancePrint(log, () -> {
                return "零部件详情,通过oid,otype查询tyPartAllVO";
            });
            TyplmLoggerUtil.debug(log, () -> {
                return "零部件详情 通过oid otype查询tyPartAllVO结果 <== tyPartAllVO : 【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(tyPartAllVO)};
            });
            if (ObjectUtils.isEmpty(tyPartAllVO)) {
                return null;
            } else {
                Map<String, Long> permissionMap = this.buildPermissionMap(Lists.newArrayList(new TyPartAllVO[]{tyPartAllVO}));
                BeanUtil.copyProperties(tyPartAllVO, partDetailsVO, new String[0]);
                if (MapUtil.isNotEmpty(permissionMap)) {
                    partDetailsVO.setPermission((Long)permissionMap.get(partDetailsVO.getOid()));
                }

                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 通过零部件oid otype查询IBA ==> oid : 【{}】, oType : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(oid), partDetailsVO.getOtype()};
                });
                TyplmLoggerUtil.performanceStart();
                Map<String, List<String>> ibaAttribute = this.typlmAttributeService.getIbaAttributeMap(oid, partDetailsVO.getOtype());
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,通过零部件oid,otype查询IBA";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 通过零部件oid otype查询IBA 结果 <== ibaAttribute : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(ibaAttribute)};
                });
                PartDO partDO = this.getLatestVersionCoStatusPart(oid.toString());
                partDetailsVO.setFolderId(partDO.getSubfolderoid());
                partDetailsVO.setSubfolderotype(partDO.getSubfolderotype());
                partDetailsVO.setSubfolderoid(partDO.getSubfolderoid());
                partDetailsVO.setIbaAttributeMap(ibaAttribute);
                partDetailsVO.setName(tyPartAllVO.getMasterName());
                partDetailsVO.setNumber(tyPartAllVO.getMasterPartNumber());
                partDetailsVO.setCheckoutState(tyPartAllVO.getLockstateinfo());
                partDetailsVO.setLifecycleMasterName(tyPartAllVO.getLifecycleTemplateName());
                partDetailsVO.setLifecycleTemplateID(tyPartAllVO.getLifecycletemplateoid().toString());
                partDetailsVO.setIteration(tyPartAllVO.getIterationid());
                List<BigInteger> folderIdList = new ArrayList();
                folderIdList.add(partDetailsVO.getFolderId());
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询文件夹路径 ==> folderIdList : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(folderIdList)};
                });
                TyplmLoggerUtil.performanceStart();
                Map<BigInteger, String> bigIntegerStringMap = this.typlmProductFolderService.recursiveQueryFolderPathByIdList(folderIdList);
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询文件夹路径";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询文件夹路径结果 <== map : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(bigIntegerStringMap)};
                });
                partDetailsVO.setFolderPath((String)bigIntegerStringMap.get(partDetailsVO.getFolderId()));
                partDetailsVO.setUnit(tyPartAllVO.getDefaultunitkey());
                partDetailsVO.setPartView(tyPartAllVO.getViewname());
                partDetailsVO.setViewDefOid(tyPartAllVO.getViewdefoid().toString());
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询生命周期状态枚举 ==> Lifecyclestagekey : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(tyPartAllVO.getLifecyclestagekey())};
                });
                TyplmLoggerUtil.performanceStart();
                Map<String, String> maps = this.typlmLocalePropertyValueService.queryLocaleValueByItem(Arrays.asList(tyPartAllVO.getLifecyclestagekey()), "LifeCycleState", TyCommonExtUtil.getFrontLanguage());
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询生命周期状态枚举";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询生命周期状态枚举 <== maps : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(maps)};
                });
                partDetailsVO.setLifecycleStateKey(tyPartAllVO.getLifecyclestagekey());
                partDetailsVO.setLifecycleState(StringUtils.isNotEmpty((CharSequence)maps.get(tyPartAllVO.getLifecyclestagekey())) ? (String)maps.get(tyPartAllVO.getLifecyclestagekey()) : tyPartAllVO.getLifecyclestagekey());
                partDetailsVO.setSource(tyPartAllVO.getSourcekey());
                partDetailsVO.setAssemblyMode(tyPartAllVO.getParttypekey());
                partDetailsVO.setTypeOid(tyPartAllVO.getTypeoid().toString());
                partDetailsVO.setTypeOtype(tyPartAllVO.getTypeotype());
                if (Objects.nonNull(tyPartAllVO.getTypeoid())) {
                    TypeVueVO typeVueVO = this.getTypeName(tyPartAllVO.getTypeoid());
                    if (Objects.nonNull(typeVueVO)) {
                        partDetailsVO.setTypeName(typeVueVO.getDisplayName());
                        partDetailsVO.setTypeInthid(typeVueVO.getInthid());
                    }
                }

                partDetailsVO.setType("part");
                if ("0".equals(partDetailsVO.getLockeroid())) {
                    partDetailsVO.setLockdate((Date)null);
                }

                List<String> userNameList = new ArrayList();
                userNameList.add(tyPartAllVO.getCreatorname());
                userNameList.add(tyPartAllVO.getUpdatorname());
                if (StringUtils.isNotBlank(tyPartAllVO.getLockername())) {
                    userNameList.add(tyPartAllVO.getLockername());
                }

                userNameList.add(tyPartAllVO.getOwnername());
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询用户 ==> userNameList : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(userNameList)};
                });
                TyplmLoggerUtil.performanceStart();
                List<UserDO> userDOS = this.typlmUserService.queryUserListByName(userNameList);
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,根据userNameList查询用户";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询用户结果 <== userDOS : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(userDOS)};
                });
                Map<String, UserDO> pdmUserMap = (Map)userDOS.stream().collect(Collectors.toMap(CTyEntityBaseDO::getName, Function.identity()));
                partDetailsVO.setCreatorName(tyPartAllVO.getCreatorname());
                partDetailsVO.setCreatorFullName(org.apache.commons.lang3.ObjectUtils.isNotEmpty(tyPartAllVO.getCreatorname()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getCreatorname())).getFullname() : "");
                partDetailsVO.setModifierName(tyPartAllVO.getUpdatorname());
                partDetailsVO.setModifierFullName(org.apache.commons.lang3.ObjectUtils.isNotEmpty(tyPartAllVO.getUpdatorname()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getUpdatorname())).getFullname() : "");
                partDetailsVO.setLockeroName(tyPartAllVO.getLockername());
                partDetailsVO.setLockeroFullName(org.apache.commons.lang3.ObjectUtils.isNotEmpty(tyPartAllVO.getLockername()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getLockername())).getFullname() : "");
                partDetailsVO.setOwnerFullName(!ObjectUtils.isEmpty(tyPartAllVO.getOwnername()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getOwnername())).getFullname() : "");
                partDetailsVO.setCreationTime(tyPartAllVO.getCreatestampstr());
                partDetailsVO.setModifyTime(tyPartAllVO.getUpdatestampstr());
                partDetailsVO.setSecurity(tyPartAllVO.getSecuritylabels());
                this.getClassInfo(partDetailsVO);
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询容器 ==> containerOtype : 【{}】, containerOid : 【{}】";
                }, () -> {
                    return new Object[]{tyPartAllVO.getContainerotype(), String.valueOf(tyPartAllVO.getContaineroid())};
                });
                TyplmLoggerUtil.performanceStart();
                CTyEntityBaseDO container = this.typlmContainerService.getContainerByID(tyPartAllVO.getContainerotype(), tyPartAllVO.getContaineroid());
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询容器";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询容器结果 <== container : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(container)};
                });
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(container)) {
                    partDetailsVO.setContainerName(container.getName());
                    partDetailsVO.setContaineroid(container.getOid().toString());
                    partDetailsVO.setContainerotype(container.getOtype());
                }

                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询设置缩略图 ==> oid : 【{}】, partDetailsVO : 【{}】, tyPartAllVO : 【{}】";
                }, () -> {
                    return new Object[]{String.valueOf(oid), JSONObject.toJSONString(partDetailsVO), JSONObject.toJSONString(tyPartAllVO)};
                });
                TyplmLoggerUtil.performanceStart();
                this.setPartThumbnailFile(oid, partDetailsVO, tyPartAllVO);
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询设置缩略图";
                });
                partDetailsVO.setIslastiterated("N");
                BomCondition bomCondition = new BomCondition();
                bomCondition.setMasteredoid(new BigInteger(partDetailsVO.getMasteredoid()));
                bomCondition.setViewdefoid(new BigInteger(partDetailsVO.getViewDefOid()));
                bomCondition.setVariation1(partDetailsVO.getVariation1());
                bomCondition.setVariation2(partDetailsVO.getVariation2());
                BigInteger latestPartVersion = this.getLatestPartVersion(bomCondition);
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(latestPartVersion) && latestPartVersion.equals(oid)) {
                    partDetailsVO.setIslastiterated("Y");
                }

                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询是否已上载 ==> oid : 【{}】";
                }, () -> {
                    return new Object[]{String.valueOf(oid)};
                });
                TyplmLoggerUtil.performanceStart();
                Map<BigInteger, List<CADInitialCheckinDataDO>> bigIntegerListMap = this.typlmCADInitialCheckinDataService.queryCADInitialCheckinDataByAObj(Arrays.asList(oid));
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询是否已上载";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询是否已上载 <== map : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(bigIntegerListMap)};
                });
                if (MapUtil.isNotEmpty(bigIntegerListMap)) {
                    partDetailsVO.setIsInitialcheckin("1");
                }

                partDetailsVO.setCompanyversion(tyPartAllVO.getCompanyversion());
                partDetailsVO.setGenericType(tyPartAllVO.getGenerictype());
                partDetailsVO.setCollapsible(tyPartAllVO.getCollapsible());
                partDetailsVO.setHistoryVersion(!"Y".equalsIgnoreCase(tyPartAllVO.getIsLatest()));
                partDetailsVO.setIcon(tyPartAllVO.getTypeIcon());
                TyplmLoggerUtil.performanceStart();
                this.partBomUtils.buildBomDisplayName(partDetailsVO);
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,构建bom用途、备用bom显示名称";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 返回结果 <== partDetailsVO : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(partDetailsVO)};
                });
                return partDetailsVO;
            }
        }
    }

    public PartDetailsVO queryPartDetailsNoPermission(BigInteger oid, String oType) {
        PartDetailsVO partDetailsVO = new PartDetailsVO();
        if (ObjectUtils.isEmpty(oid)) {
            return null;
        } else {
            TyplmLoggerUtil.debug(log, () -> {
                return "零部件详情 通过oid otype查询tyPartAllVO ==> oid : 【{}】, oType : 【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(oid), oType};
            });
            TyplmLoggerUtil.performanceStart();
            TyPartAllVO tyPartAllVO = this.typlmPartService.queryPartAllVO(oid, oType);
            TyplmLoggerUtil.performancePrint(log, () -> {
                return "零部件详情,通过oid,otype查询tyPartAllVO";
            });
            TyplmLoggerUtil.debug(log, () -> {
                return "零部件详情 通过oid otype查询tyPartAllVO结果 <== tyPartAllVO : 【{}】";
            }, () -> {
                return new Object[]{JSONObject.toJSONString(tyPartAllVO)};
            });
            if (ObjectUtils.isEmpty(tyPartAllVO)) {
                return null;
            } else {
                BeanUtil.copyProperties(tyPartAllVO, partDetailsVO, new String[0]);
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 通过零部件oid otype查询IBA ==> oid : 【{}】, oType : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(oid), partDetailsVO.getOtype()};
                });
                TyplmLoggerUtil.performanceStart();
                Map<String, List<String>> ibaAttribute = this.typlmAttributeService.getIbaAttributeMap(oid, partDetailsVO.getOtype());
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,通过零部件oid,otype查询IBA";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 通过零部件oid otype查询IBA 结果 <== ibaAttribute : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(ibaAttribute)};
                });
                PartDO partDO = this.getLatestVersionCoStatusPart(oid.toString());
                partDetailsVO.setFolderId(partDO.getSubfolderoid());
                partDetailsVO.setSubfolderotype(partDO.getSubfolderotype());
                partDetailsVO.setSubfolderoid(partDO.getSubfolderoid());
                partDetailsVO.setCheckoutState(tyPartAllVO.getLockstateinfo());
                partDetailsVO.setIbaAttributeMap(ibaAttribute);
                partDetailsVO.setName(tyPartAllVO.getMasterName());
                partDetailsVO.setNumber(tyPartAllVO.getMasterPartNumber());
                partDetailsVO.setLifecycleMasterName(tyPartAllVO.getLifecycleTemplateName());
                partDetailsVO.setLifecycleTemplateID(tyPartAllVO.getLifecycletemplateoid().toString());
                partDetailsVO.setIteration(tyPartAllVO.getIterationid());
                List<BigInteger> folderIdList = new ArrayList();
                folderIdList.add(partDetailsVO.getFolderId());
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询文件夹路径 ==> folderIdList : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(folderIdList)};
                });
                TyplmLoggerUtil.performanceStart();
                Map<BigInteger, String> bigIntegerStringMap = this.typlmProductFolderService.recursiveQueryFolderPathByIdList(folderIdList);
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询文件夹路径";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询文件夹路径结果 <== map : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(bigIntegerStringMap)};
                });
                partDetailsVO.setFolderPath((String)bigIntegerStringMap.get(partDetailsVO.getFolderId()));
                partDetailsVO.setUnit(tyPartAllVO.getDefaultunitkey());
                partDetailsVO.setPartView(tyPartAllVO.getViewname());
                partDetailsVO.setViewDefOid(tyPartAllVO.getViewdefoid().toString());
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询生命周期状态枚举 ==> Lifecyclestagekey : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(tyPartAllVO.getLifecyclestagekey())};
                });
                TyplmLoggerUtil.performanceStart();
                Map<String, String> maps = this.typlmLocalePropertyValueService.queryLocaleValueByItem(Arrays.asList(tyPartAllVO.getLifecyclestagekey()), "LifeCycleState", TyCommonExtUtil.getFrontLanguage());
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询生命周期状态枚举";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询生命周期状态枚举 <== maps : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(maps)};
                });
                partDetailsVO.setLifecycleStateKey(tyPartAllVO.getLifecyclestagekey());
                partDetailsVO.setLifecycleState(StringUtils.isNotEmpty((CharSequence)maps.get(tyPartAllVO.getLifecyclestagekey())) ? (String)maps.get(tyPartAllVO.getLifecyclestagekey()) : tyPartAllVO.getLifecyclestagekey());
                partDetailsVO.setTypeOtype(tyPartAllVO.getTypeotype());
                partDetailsVO.setSource(tyPartAllVO.getSourcekey());
                partDetailsVO.setAssemblyMode(tyPartAllVO.getParttypekey());
                partDetailsVO.setTypeOid(tyPartAllVO.getTypeoid().toString());
                if (Objects.nonNull(tyPartAllVO.getTypeoid())) {
                    TypeVueVO typeVueVO = this.getTypeName(tyPartAllVO.getTypeoid());
                    if (Objects.nonNull(typeVueVO)) {
                        partDetailsVO.setTypeName(typeVueVO.getDisplayName());
                        partDetailsVO.setTypeInthid(typeVueVO.getInthid());
                    }
                }

                partDetailsVO.setType("part");
                if ("0".equals(partDetailsVO.getLockeroid())) {
                    partDetailsVO.setLockdate((Date)null);
                }

                List<String> userNameList = new ArrayList();
                userNameList.add(tyPartAllVO.getCreatorname());
                userNameList.add(tyPartAllVO.getUpdatorname());
                if (StringUtils.isNotBlank(tyPartAllVO.getLockername())) {
                    userNameList.add(tyPartAllVO.getLockername());
                }

                userNameList.add(tyPartAllVO.getOwnername());
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询用户 ==> userNameList : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(userNameList)};
                });
                TyplmLoggerUtil.performanceStart();
                List<UserDO> userDOS = this.typlmUserService.queryUserListByName(userNameList);
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,根据userNameList查询用户";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询用户结果 <== userDOS : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(userDOS)};
                });
                Map<String, UserDO> pdmUserMap = (Map)userDOS.stream().collect(Collectors.toMap(CTyEntityBaseDO::getName, Function.identity()));
                partDetailsVO.setCreatorName(tyPartAllVO.getCreatorname());
                partDetailsVO.setCreatorFullName(org.apache.commons.lang3.ObjectUtils.isNotEmpty(tyPartAllVO.getCreatorname()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getCreatorname())).getFullname() : "");
                partDetailsVO.setModifierName(tyPartAllVO.getUpdatorname());
                partDetailsVO.setModifierFullName(org.apache.commons.lang3.ObjectUtils.isNotEmpty(tyPartAllVO.getUpdatorname()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getUpdatorname())).getFullname() : "");
                partDetailsVO.setLockeroName(tyPartAllVO.getLockername());
                partDetailsVO.setLockeroFullName(org.apache.commons.lang3.ObjectUtils.isNotEmpty(tyPartAllVO.getLockername()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getLockername())).getFullname() : "");
                partDetailsVO.setOwnerFullName(!ObjectUtils.isEmpty(tyPartAllVO.getOwnername()) ? ((UserDO)pdmUserMap.get(tyPartAllVO.getOwnername())).getFullname() : "");
                partDetailsVO.setCreationTime(tyPartAllVO.getCreatestampstr());
                partDetailsVO.setModifyTime(tyPartAllVO.getUpdatestampstr());
                partDetailsVO.setSecurity(tyPartAllVO.getSecuritylabels());
                this.getClassInfo(partDetailsVO);
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询容器 ==> containerOtype : 【{}】, containerOid : 【{}】";
                }, () -> {
                    return new Object[]{tyPartAllVO.getContainerotype(), String.valueOf(tyPartAllVO.getContaineroid())};
                });
                TyplmLoggerUtil.performanceStart();
                CTyEntityBaseDO container = this.typlmContainerService.getContainerByID(tyPartAllVO.getContainerotype(), tyPartAllVO.getContaineroid());
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询容器";
                });
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询容器结果 <== container : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(container)};
                });
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(container)) {
                    partDetailsVO.setContainerName(container.getName());
                    partDetailsVO.setContaineroid(container.getOid().toString());
                    partDetailsVO.setContainerotype(container.getOtype());
                }

                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 查询设置缩略图 ==> oid : 【{}】, partDetailsVO : 【{}】, tyPartAllVO : 【{}】";
                }, () -> {
                    return new Object[]{String.valueOf(oid), JSONObject.toJSONString(partDetailsVO), JSONObject.toJSONString(tyPartAllVO)};
                });
                TyplmLoggerUtil.performanceStart();
                TyplmLoggerUtil.performancePrint(log, () -> {
                    return "零部件详情,查询设置缩略图";
                });
                partDetailsVO.setIslastiterated("N");
                BomCondition bomCondition = new BomCondition();
                bomCondition.setMasteredoid(new BigInteger(partDetailsVO.getMasteredoid()));
                bomCondition.setViewdefoid(new BigInteger(partDetailsVO.getViewDefOid()));
                bomCondition.setVariation1(partDetailsVO.getVariation1());
                bomCondition.setVariation2(partDetailsVO.getVariation2());
                BigInteger latestPartVersion = this.getLatestPartVersion(bomCondition);
                if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(latestPartVersion) && latestPartVersion.equals(oid)) {
                    partDetailsVO.setIslastiterated("Y");
                }

                partDetailsVO.setCompanyversion(tyPartAllVO.getCompanyversion());
                partDetailsVO.setGenericType(tyPartAllVO.getGenerictype());
                partDetailsVO.setCollapsible(tyPartAllVO.getCollapsible());
                partDetailsVO.setHistoryVersion(!"Y".equalsIgnoreCase(tyPartAllVO.getIsLatest()));
                return partDetailsVO;
            }
        }
    }

    public LayoutInfoVO queryPartDetailsByLayoutInfo(BigInteger oid, String otype) {
        LayoutInfoVO layoutInfoVO = new LayoutInfoVO();
        if (!TyplmEntityBaseUtil.isEmptyOid(oid) && StringUtils.isNotBlank(otype)) {
            TyplmLoggerUtil.debug(log, () -> {
                return "queryPartDetailsByLayoutInfo  ==> 查询部件条件,oid,otype =【{}】";
            }, () -> {
                return new Object[]{JSON.toJSONString(oid), JSON.toJSONString(otype)};
            });
            PartDetailsVO partDetailsVO = this.queryPartDetails(oid, otype);
            TyplmLoggerUtil.debug(log, () -> {
                return "queryPartDetailsByLayoutInfo  ==> 查询部件条件 =【{}】";
            }, () -> {
                return new Object[]{JSON.toJSONString(partDetailsVO)};
            });
            layoutInfoVO = this.paresPartDetailsVOLayoutInfoVO(partDetailsVO);
            LayoutInfoVO finalLayoutInfoVO = layoutInfoVO;
            TyplmLoggerUtil.debug(log, () -> {
                return "queryPartDetailsByLayoutInfo  ==> 查询部件条件 =【{}】";
            }, () -> {
                return new Object[]{JSON.toJSONString(finalLayoutInfoVO)};
            });
        }

        return layoutInfoVO;
    }

    public LayoutInfoVO paresPartDetailsVOLayoutInfoVO(PartDetailsVO partDetails) {
        LayoutInfoVO result = new LayoutInfoVO();
        if (ObjectUtil.isEmpty(partDetails)) {
            return result;
        } else {
            PartDetailsLayoutVO partDetailsVO = this.paresPartDetailsLayoutVO(partDetails);
            TyplmLayoutUtil.buildAttributeValueJsonObject(partDetailsVO, PartDetailsLayoutVO.class);
            result.setIbaMap(partDetailsVO.getIbaMap());
            result.setAttrList(partDetailsVO.getAttrList());
            result.setOid(TyplmEntityBaseUtil.getOidByStr(partDetailsVO.getOid(), (BigInteger)null));
            result.setOtype(partDetailsVO.getOtype());
            result.setTypeOid(TyplmEntityBaseUtil.getOidByStr(partDetailsVO.getTypeOid(), (BigInteger)null));
            BigInteger classId = partDetailsVO.getClassId();
            if (!TyplmEntityBaseUtil.isEmptyOid(classId)) {
                result.setClassificationOid(classId);
                result.setClassificationOtype("ty.inteplm.type.CTyClassification");
            }

            result.setTypeOtype(partDetailsVO.getTypeOtype());
            result.setTypeInthid(partDetailsVO.getTypeInthid());
            result.setLifecyclestagekeyName(partDetailsVO.getLifecycleState());
            result.setLockstateinfo(partDetailsVO.getLockstateinfo());
            result.setIdentifier(partDetailsVO.getIdentifierDisplayName());
            Boolean islastiterated = partDetailsVO.getIsVersionInfo();
            String islastiteratedStr = "0";
            if (Boolean.TRUE.equals(islastiterated)) {
                islastiteratedStr = "1";
            }

            result.setIslastiterated(islastiteratedStr);
            result.setLockerFullName(partDetailsVO.getLockeroFullName());
            result.setLockerName(partDetailsVO.getLockeroName());
            result.setTypeDefName(partDetailsVO.getTypeName());
            result.setContainerOid(TyplmEntityBaseUtil.getOidByStr(partDetailsVO.getContaineroid(), (BigInteger)null));
            result.setContainerOtype(partDetailsVO.getContainerotype());
            return result;
        }
    }

    public PartDetailsLayoutVO paresPartDetailsLayoutVO(PartDetailsVO obj) {
        PartDetailsLayoutVO partDetailsLayoutVO = (PartDetailsLayoutVO)BeanUtil.copyProperties(obj, PartDetailsLayoutVO.class, new String[0]);
        partDetailsLayoutVO.setView(obj.getDisplayView());
        ReferenceBaseDTO viewRef = new ReferenceBaseDTO();
        viewRef.setOid(TyplmEntityBaseUtil.getOidByStr(obj.getViewDefOid(), (BigInteger)null));
        viewRef.setOtype("ty.inteplm.view.CTyViewDef");
        viewRef.setText(obj.getPartView());
        viewRef.setValue(viewRef.getOtype() + ":" + viewRef.getOid());
        partDetailsLayoutVO.setViewRef(viewRef);
        ReferenceBaseDTO typeDefName = new ReferenceBaseDTO();
        typeDefName.setOid(TyplmEntityBaseUtil.getOidByStr(obj.getTypeOid(), (BigInteger)null));
        typeDefName.setOtype("ty.inteplm.type.CTyTypeDef");
        typeDefName.setText(obj.getTypeName());
        typeDefName.setValue(typeDefName.getOtype() + ":" + typeDefName.getOid());
        partDetailsLayoutVO.setTypeDefName(typeDefName);
        ReferenceBaseDTO classDefName = new ReferenceBaseDTO();
        classDefName.setOid(obj.getClassId());
        classDefName.setOtype("ty.inteplm.type.CTyClassification");
        classDefName.setText(obj.getClassDisplayName());
        classDefName.setValue(classDefName.getOtype() + ":" + classDefName.getOid());
        if (!TyplmEntityBaseUtil.isEmptyOid(classDefName.getOid())) {
            partDetailsLayoutVO.setClassDefName(classDefName);
        }

        ReferenceBaseDTO lifeCycleTemplateRef = new ReferenceBaseDTO();
        lifeCycleTemplateRef.setOid(TyplmEntityBaseUtil.getOidByStr(obj.getLifecycleTemplateID(), (BigInteger)null));
        lifeCycleTemplateRef.setOtype("ty.inteplm.lifecycle.CTyLifecycleTemplate");
        lifeCycleTemplateRef.setText(obj.getLifecycleMasterName());
        lifeCycleTemplateRef.setValue(lifeCycleTemplateRef.getOtype() + ":" + lifeCycleTemplateRef.getOid());
        partDetailsLayoutVO.setLifeCycleTemplateRef(lifeCycleTemplateRef);
        ReferenceBaseDTO owner = new ReferenceBaseDTO();
        owner.setOid(obj.getOwneroid());
        owner.setOtype("ty.inteplm.org.CTyUser");
        owner.setText(obj.getOwnerFullName());
        owner.setValue(obj.getOwnername());
        partDetailsLayoutVO.setOwner(owner);
        ReferenceBaseDTO creator = new ReferenceBaseDTO();
        creator.setOid(obj.getCreatoroid());
        creator.setOtype("ty.inteplm.org.CTyUser");
        creator.setText(obj.getCreatorFullName());
        creator.setValue(obj.getCreatorName());
        partDetailsLayoutVO.setCreator(creator);
        ReferenceBaseDTO updator = new ReferenceBaseDTO();
        updator.setOid(obj.getUpdatoroid());
        updator.setOtype("ty.inteplm.org.CTyUser");
        updator.setText(obj.getModifierFullName());
        updator.setValue(obj.getModifierName());
        partDetailsLayoutVO.setUpdator(updator);
        ReferenceBaseDTO containerRef = new ReferenceBaseDTO();
        containerRef.setOid(obj.getCreatoroid());
        containerRef.setOtype(obj.getContainerotype());
        containerRef.setText(obj.getContainerName());
        containerRef.setValue(containerRef.getOtype() + ":" + containerRef.getOid());
        partDetailsLayoutVO.setContainerRef(containerRef);
        partDetailsLayoutVO.setIbaAttributeMap(obj.getIbaAttributeMap());
        ReferenceBaseDTO folderRef = new ReferenceBaseDTO();
        folderRef.setOid(obj.getSubfolderoid());
        folderRef.setOtype("ty.inteplm.folder.CTySubFolder");
        folderRef.setText(obj.getFolderPath());
        folderRef.setValue(folderRef.getOtype() + ":" + folderRef.getOid());
        partDetailsLayoutVO.setFolder(folderRef);
        if (StringUtils.isNotBlank(obj.getLockeroid())) {
            ReferenceBaseDTO locker = new ReferenceBaseDTO();
            locker.setOid(TyplmEntityBaseUtil.getOidByStr(obj.getLockeroid(), (BigInteger)null));
            locker.setOtype("ty.inteplm.org.CTyUser");
            locker.setText(obj.getLockeroFullName());
            locker.setValue(obj.getLockeroName());
            partDetailsLayoutVO.setLocker(locker);
        }

        partDetailsLayoutVO.setCheckoutState(TyplmLayoutUtil.pareseCheckoutStatus(obj.getCheckoutState(), CommonUtil.getUser().getName(), obj.getLockeroName()));
        partDetailsLayoutVO.setIslastiterated(TyplmLayoutUtil.pareseIslastiterated(partDetailsLayoutVO.getIslastiterated()));
        return partDetailsLayoutVO;
    }

    private void setPartThumbnailFile(BigInteger oid, PartDetailsVO partDetailsVO, TyPartAllVO tyPartAllVO) {
        List<BigInteger> idList = new ArrayList();
        idList.add(oid);
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询轻量化文件 ==> idList : 【{}】, tyPartAllVO.getOtype() : 【{}】, Constant.ALL : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(idList), tyPartAllVO.getOtype(), "ALL"};
        });
        TyplmLoggerUtil.performanceStart();
        Map<String, List<ContentDataFileVO>> contentDataMap = this.typlmContentDataService.queryContentDataByDocOidsAndType(idList, tyPartAllVO.getOtype(), "ALL");
        TyplmLoggerUtil.performancePrint(log, () -> {
            return "零部件详情,查询轻量化文件";
        });
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询轻量化文件结果 <== contentDataMap : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(contentDataMap)};
        });
        List<ContentDataFileVO> contentDataFileVoList = (List)contentDataMap.get(oid.toString());
        if (CollUtil.isNotEmpty(contentDataFileVoList)) {
            List<ContentDataFileVO> collect = (List)contentDataFileVoList.stream().filter((contentDataFileVo) -> {
                return "THUMBNAIL".equals(contentDataFileVo.getRolekey());
            }).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(collect)) {
                partDetailsVO.setThumbnailFile(FileConvertUtils.buildFile((ContentDataFileVO)collect.get(0)));
            } else {
                TyplmLoggerUtil.debug(log, () -> {
                    return "零部件详情 如果有文件但是没有缩略图取主控文档 ==> oid : 【{}】, partDetailsVO : 【{}】";
                }, () -> {
                    return new Object[]{JSONObject.toJSONString(oid), JSONObject.toJSONString(partDetailsVO)};
                });
                this.getDocThumbnailFile(oid, partDetailsVO);
            }
        } else {
            this.getDocThumbnailFile(oid, partDetailsVO);
        }

    }

    public void getClassInfo(PartDetailsVO partDetailsVO) {
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 获取分类 ==> 零部件masteredoid : 【{}】, 零部件masteredotype : 【{}】";
        }, () -> {
            return new Object[]{partDetailsVO.getMasteredoid(), partDetailsVO.getMasteredotype()};
        });
        Map<String, Object> classificationInfoMap = this.typlmClassificationService.queryClassNameByCondition(new BigInteger(partDetailsVO.getMasteredoid()), partDetailsVO.getMasteredotype());
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 获取分类 <== classificationInfoMap : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(classificationInfoMap)};
        });
        if (MapUtil.isNotEmpty(classificationInfoMap)) {
            if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(classificationInfoMap.get("oid"))) {
                partDetailsVO.setClassId((BigInteger)classificationInfoMap.get("oid"));
            }

            if (org.apache.commons.lang3.ObjectUtils.isNotEmpty(classificationInfoMap.get("displayName"))) {
                partDetailsVO.setClassDisplayName(classificationInfoMap.get("displayName").toString());
            }
        }

    }

    public BigInteger getLatestPartVersion(BomCondition bomCondition) {
        LatestPartVersionVO latestPartVersion = this.typlmPartMapper.getLatestPartVersionID(bomCondition, CommonUtil.getUserOid());
        return ObjectUtil.isNotEmpty(latestPartVersion) ? latestPartVersion.getLatestPartVersionID() : null;
    }

    private TypeVueVO getTypeName(BigInteger typeOid) {
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询类型名称 ==> typeOid : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(typeOid)};
        });
        List<TypeVueVO> typeVueVOS = this.typlmTypeExtService.queryTypeByIds(Collections.singletonList(typeOid));
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询类型名称 <== typeVueVOS : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(typeVueVOS)};
        });
        return CollUtil.isNotEmpty(typeVueVOS) ? (TypeVueVO)typeVueVOS.get(0) : null;
    }

    private PartDO getLatestVersionCoStatusPart(String oId) {
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询零部件历史 ==> oId : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(oId)};
        });
        List<PartDO> partDOS = this.typlmPartService.queryPartHistory(new BigInteger(oId), "");
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 查询零部件历史结果 <== partDOS : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(partDOS)};
        });
        PartDO partDO = (PartDO)partDOS.stream().filter((m) -> {
            return m.getOid().equals(new BigInteger(oId));
        }).findFirst().orElse(new PartDO());
        Iterator var4 = partDOS.iterator();

        while(var4.hasNext()) {
            PartDO history = (PartDO)var4.next();
            if (history.getVersion().equals(partDO.getVersion()) && history.getIterationid().equals(partDO.getIterationid()) && history.getLockstateinfo().equals("c/o")) {
                partDO = history;
                break;
            }
        }

        if (TyAccountContext.isDebug()) {
            log.info("零部件详情 如果是wrk取出CO状态 <== partDO : 【{}】", JSONObject.toJSONString(partDO));
        }

        return partDO;
    }

    private void getDocThumbnailFile(BigInteger oid, PartDetailsVO partDetailsVO) {
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 取主控文档 ==> oid : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(oid)};
        });
        TyplmLoggerUtil.performanceStart();
        DocDetails masterControlDoc = this.typlmPartRelObjectService.queryMasterControlCadByPartId(oid);
        TyplmLoggerUtil.performancePrint(log, () -> {
            return "零部件详情取主控文档";
        });
        TyplmLoggerUtil.debug(log, () -> {
            return "零部件详情 取主控文档 <== masterControlDoc : 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(masterControlDoc)};
        });
        if (CollUtil.isNotEmpty(masterControlDoc.getPrimaryFileList()) && Objects.nonNull(masterControlDoc.getPrimaryFileList().get(0)) && CollUtil.isNotEmpty(((FileDataVO)masterControlDoc.getPrimaryFileList().get(0)).getFileDataVOList())) {
            partDetailsVO.setThumbnailFile((FileDataVO)((FileDataVO)masterControlDoc.getPrimaryFileList().get(0)).getFileDataVOList().stream().filter((fileData) -> {
                return "THUMBNAIL".equalsIgnoreCase(fileData.getRolekey());
            }).findFirst().orElse(new FileDataVO()));
        }

    }

    private List<BigInteger> getHasPremissionOid(List<ParamIdDTO> paramIdDTOList, UserDO user) {
        List<BigInteger> partIds = new ArrayList();
        List<String> partIdStrs = new ArrayList();
        paramIdDTOList.forEach((dto) -> {
            partIds.add(CommonUtil.stringToBigIntegers(dto.getId()));
            partIdStrs.add(dto.getId());
        });
        if (CollectionUtils.isEmpty(partIds)) {
            return partIds;
        } else {
            List<PartDO> partDOS = this.queryPartByIDs(partIdStrs);
            if (CollectionUtils.isEmpty(partDOS)) {
                return partIds;
            } else {
                List<String> permissionList = new ArrayList();

                for(int i = 0; i < partDOS.size(); ++i) {
                    permissionList.add("读取");
                }

                List<String> noPermissionOids = this.typlmPermissionsUtil.getNoPermissionOids(user, new ArrayList(partDOS), permissionList);
                return (List)partIds.stream().filter((partId) -> {
                    return !noPermissionOids.contains(partId.toString());
                }).distinct().collect(Collectors.toList());
            }
        }
    }

    private List<PartDetailVO> batchQueryPartBasicAttrs(List<BigInteger> partIds, UserDO user) {
        List<PartDetailVO> partDetailVOs = this.typlmPartMapper.batchQueryPartBasicAttrs(partIds);
        if (Objects.isNull(partDetailVOs)) {
            return partDetailVOs;
        } else {
            List<String> lifeCycleStateCode = (List)partDetailVOs.stream().map(PartBasicAttrsInfoVO::getLifeCycleStageCode).distinct().collect(Collectors.toList());
            List<String> assemblyModeCode = (List)partDetailVOs.stream().map(PartBasicAttrsInfoVO::getAssemblyModeCode).distinct().collect(Collectors.toList());
            Map<String, String> lifeCycleStageMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(lifeCycleStateCode, "LifeCycleState", TyCommonExtUtil.getFrontLanguage());
            Map<String, String> assemblyModeMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(assemblyModeCode, "AssemblyMode", TyCommonExtUtil.getFrontLanguage());
            partDetailVOs.forEach((partDetailVOx) -> {
                partDetailVOx.setLifeCycleStageName((String)lifeCycleStageMap.get(partDetailVOx.getLifeCycleStageCode()));
                partDetailVOx.setAssemblyModeName((String)assemblyModeMap.get(partDetailVOx.getAssemblyModeCode()));
            });
            List<LatestPartVersionVO> latestPartVersionVOS = this.batchGetLatestPartVersionID(partIds, user.getOid());
            Map<String, List<LatestPartVersionVO>> latestPartMap = (Map)latestPartVersionVOS.stream().collect(Collectors.groupingBy(LatestPartVersionVO::getPartVersionID));
            Iterator var10 = partDetailVOs.iterator();

            while(var10.hasNext()) {
                PartDetailVO partDetailVO = (PartDetailVO)var10.next();
                if (latestPartMap.containsKey(partDetailVO.getId())) {
                    String latestPartVersionId = String.valueOf(((LatestPartVersionVO)((List)latestPartMap.get(partDetailVO.getId())).get(0)).getLatestPartVersionID());
                    String latestVersion = String.valueOf(((LatestPartVersionVO)((List)latestPartMap.get(partDetailVO.getId())).get(0)).getVersion());
                    partDetailVO.setIsLatest("N");
                    String partVersion = partDetailVO.getVersion().concat(".").concat(partDetailVO.getIteration());
                    if (latestVersion.equals(partVersion)) {
                        partDetailVO.setIsLatest("Y");
                    }

                    partDetailVO.setLatestPartVersionId(latestPartVersionId);
                }
            }

            return partDetailVOs;
        }
    }

    private void setFolderPath(List<PartDetailVO> partDetailVOS) {
        List<String> sourceIds = new ArrayList();
        partDetailVOS.forEach((vo) -> {
            if ("wrk".equals(vo.getCheckoutState())) {
                sourceIds.add(vo.getSourceIterationOid().toString());
            }

        });
        Map<BigInteger, List<PartDO>> sourcePartMap = new HashMap();
        if (!CollectionUtils.isEmpty(sourceIds)) {
            List<PartDO> sourceParts = this.queryPartByIDs(sourceIds);
            sourcePartMap = (Map)sourceParts.stream().collect(Collectors.groupingBy(PartDO::getOid));
        }

        final Map<BigInteger, List<PartDO>> sourcePartMap1=sourcePartMap;

        List<BigInteger> folderId = new ArrayList();
        partDetailVOS.forEach((vo) -> {
            if ("wrk".equals(vo.getCheckoutState())) {
                vo.setFolderId(((PartDO)((List)sourcePartMap1.get(vo.getSourceIterationOid())).get(0)).getSubfolderoid().toString());
            }

            folderId.add(new BigInteger(vo.getFolderId()));
        });
        Map<BigInteger, String> folderPathMap = this.typlmSubFolderLinkService.recursiveQueryFolderPathByIdList(folderId);
        Iterator var7 = partDetailVOS.iterator();

        while(var7.hasNext()) {
            PartDetailVO partDetailVO = (PartDetailVO)var7.next();
            if (StringUtils.isEmpty(partDetailVO.getFolderId()) || "null".equalsIgnoreCase(partDetailVO.getFolderId())) {
                partDetailVO.setFolderId("0");
            }

            String path = "";
            path = path + (String)folderPathMap.get(new BigInteger(partDetailVO.getFolderId()));
            partDetailVO.setFolderPath(path);
        }

    }

    private Map<String, List<AttributeVO>> queryPartIBA(PartDetailAttrsDTO returnAttrsDTO, List<BigInteger> partIds) {
        Map<String, List<AttributeVO>> partIBAMap = new HashMap();
        if ("Y".equalsIgnoreCase(returnAttrsDTO.getIsReturnAllIbaAttrs())) {
            partIBAMap.putAll(this.typlmAttributeValueService.getAttrValueTableByEntitys(partIds, "ty.inteplm.part.CTyPart"));
        }

        if ("N".equalsIgnoreCase(returnAttrsDTO.getIsReturnAllIbaAttrs()) && !CollectionUtils.isEmpty(returnAttrsDTO.getIbaAttrs())) {
            partIBAMap.putAll(this.typlmAttributeValueService.getIbaAttrValueByOidAndKeys(partIds, "ty.inteplm.part.CTyPart", returnAttrsDTO.getIbaAttrs()));
        }

        return partIBAMap;
    }

    private Map<String, List<AttributeVO>> queryPartMasterIBA(PartDetailAttrsDTO returnAttrsDTO, List<PartDetailVO> partDetailVOS) {
        Map<String, List<AttributeVO>> partMasterIBAMap = new HashMap();
        List<BigInteger> partMasterIds = new ArrayList();
        partDetailVOS.forEach((partDetailVO) -> {
            partMasterIds.add(partDetailVO.getMasteredoid());
        });
        if ("Y".equalsIgnoreCase(returnAttrsDTO.getIsReturnAllMasterAttrs())) {
            partMasterIBAMap.putAll(this.typlmAttributeValueService.getAttrValueTableByEntitys(partMasterIds, "ty.inteplm.part.CTyPartMaster"));
        }

        if ("N".equalsIgnoreCase(returnAttrsDTO.getIsReturnAllMasterAttrs()) && !CollectionUtils.isEmpty(returnAttrsDTO.getMasterAttrs())) {
            partMasterIBAMap.putAll(this.typlmAttributeValueService.getIbaAttrValueByOidAndKeys(partMasterIds, "ty.inteplm.part.CTyPartMaster", returnAttrsDTO.getMasterAttrs()));
        }

        return partMasterIBAMap;
    }

    private List<PartDetailResponseVO> buildPartDetailResponse(List<PartDetailVO> partDetailVOS, Map<String, List<AttributeVO>> partIBAMap, Map<String, List<AttributeVO>> partMasterIBAMap, Map<BigInteger, List<ComplexAttrsVO>> extAttrMap) {
        List<PartDetailResponseVO> responseVOS = new ArrayList();

        PartDetailResponseVO partDetailResponseVO;
        for(Iterator var6 = partDetailVOS.iterator(); var6.hasNext(); responseVOS.add(partDetailResponseVO)) {
            PartDetailVO detailVO = (PartDetailVO)var6.next();
            partDetailResponseVO = new PartDetailResponseVO();
            PartBasicAttrsInfoVO partBasicAttrsInfoVO = new PartBasicAttrsInfoVO();
            BeanUtils.copyProperties(detailVO, partBasicAttrsInfoVO);
            partBasicAttrsInfoVO.setNumber(detailVO.getPartNumber());
            partDetailResponseVO.setBasicAttrs(partBasicAttrsInfoVO);
            if (!CollectionUtils.isEmpty(partIBAMap) && partIBAMap.containsKey(detailVO.getId())) {
                partDetailResponseVO.setIbaAttrs(this.buildPartIBA((List)partIBAMap.get(detailVO.getId())));
            }

            if (!CollectionUtils.isEmpty(partMasterIBAMap) && partMasterIBAMap.containsKey(detailVO.getMasteredoid().toString())) {
                partDetailResponseVO.setMasterAttrs(this.buildPartIBA((List)partMasterIBAMap.get(detailVO.getMasteredoid().toString())));
            }

            if (!CollectionUtils.isEmpty(extAttrMap) && extAttrMap.containsKey(new BigInteger(detailVO.getId()))) {
                partDetailResponseVO.setComplexAttrs((List)extAttrMap.get(new BigInteger(detailVO.getId())));
            }
        }

        return responseVOS;
    }

    private List<IbaAttrsVO> buildPartIBA(List<AttributeVO> attributeVOS) {
        List<IbaAttrsVO> partIBAVO = new ArrayList();

        IbaAttrsVO attrsVO;
        for(Iterator var3 = attributeVOS.iterator(); var3.hasNext(); partIBAVO.add(attrsVO)) {
            AttributeVO attributeVO = (AttributeVO)var3.next();
            attrsVO = new IbaAttrsVO();
            attrsVO.setKey(RestfulUtil.changeNullToString(attributeVO.getAttributeEnName()));
            attrsVO.setDescription(RestfulUtil.changeNullToString(attributeVO.getAttributeDefDescription()));
            String language = TyCommonExtUtil.getFrontLanguage();
            if ("zh-CN".equalsIgnoreCase(language)) {
                attrsVO.setDisplayname(attributeVO.getAttributeName());
            } else {
                attrsVO.setDisplayname(attributeVO.getAttributeHierarchyName());
            }

            if (attributeVO.getOType() != null && "ty.inteplm.attribute.CTyUnitValue".equals(attributeVO.getOType())) {
                String unitType = RestfulUtil.changeNullToString(attributeVO.getUnitType());
                String value = RestfulUtil.changeNullToString(attributeVO.getAttributeValue());
                if (Strings.isNullOrEmpty(unitType)) {
                    attrsVO.setValue(value);
                } else {
                    attrsVO.setValue(value + " " + unitType);
                }
            } else if (attributeVO.getOType() != null && "ty.inteplm.attribute.CTyStringValue".equals(attributeVO.getOType())) {
                attrsVO.setValue(RestfulUtil.changeNullToString(attributeVO.getAttributeValuex()));
            } else {
                attrsVO.setValue(RestfulUtil.changeNullToString(attributeVO.getAttributeValue()));
            }
        }

        return partIBAVO;
    }

    public List<PartLinkMPNVO> batchGetPartLinkMpnByNumber(List<QueryMPNDTO> queryMPNDTOS) {
        UserDO user = CommonUtil.getUser();
        List<PartLinkMPNVO> partLinkMPNVOS = this.typlmPartQueryMapper.batchGetPartLinkMpnByNumber(queryMPNDTOS, user.getOid());
        if (!CollectionUtils.isEmpty(partLinkMPNVOS)) {
            List<String> codeList = (List)partLinkMPNVOS.stream().map(PartLinkMPNVO::getMpnBasicAttr).map(MPNBasicAttrVO::getLifecycleStateCode).collect(Collectors.toList());
            Map<String, String> codeMap = this.typlmLocalePropertyValueService.queryLocaleValueByItem(codeList, "LifeCycleState", TyCommonExtUtil.getFrontLanguage());
            partLinkMPNVOS.forEach((item) -> {
                item.getMpnBasicAttr().setLifecycleStateName((String)codeMap.get(item.getMpnBasicAttr().getLifecycleStateCode()));
            });
        }

        return partLinkMPNVOS;
    }

    public List<PartDO> queryNowBranchVersionByIdList(List<BigInteger> partIdList) {
        return this.typlmPartMapper.queryNowBranchVersionByIdList(partIdList);
    }

    public List<PartDO> queryPartByBomCondition(BomCondition bomCondition) {
        List<PartDO> result = new ArrayList();
        if (Objects.isNull(bomCondition)) {
            return result;
        } else {
            if (bomCondition.getMasteredoid() != null) {
                bomCondition.getMasteredOids().add(bomCondition.getMasteredoid());
            }

            if (CollUtil.isNotEmpty(bomCondition.getMasteredOids())) {
                List<List<BigInteger>> split = CollUtil.split(CollUtil.distinct(bomCondition.getMasteredOids()), 500);
                Iterator var4 = split.iterator();

                while(var4.hasNext()) {
                    List<BigInteger> list = (List)var4.next();
                    BomCondition condition = new BomCondition();
                    BeanUtils.copyProperties(bomCondition, condition);
                    condition.setMasteredOids(list);
                    result.addAll(this.queryByCondition(condition));
                }
            } else {
                result.addAll(this.queryByCondition(bomCondition));
            }

            return result;
        }
    }

    private List<PartDO> queryByCondition(BomCondition bomCondition) {
        Example ex = new Example(PartDO.class, true, true);
        Example.Criteria criteria = ex.createCriteria();
        if (CollUtil.isNotEmpty(bomCondition.getMasteredOids())) {
            criteria.andIn("masteredoid", bomCondition.getMasteredOids());
            criteria.andEqualTo("masteredotype", "ty.inteplm.part.CTyPartMaster");
        }

        if (bomCondition.getViewdefoid() != null) {
            criteria.andEqualTo("viewdefoid", bomCondition.getViewdefoid());
            criteria.andEqualTo("viewdefotype", "ty.inteplm.view.CTyViewDef");
        }

        if (StringUtils.isNotBlank(bomCondition.getVariation1())) {
            criteria.andEqualTo("variation1", bomCondition.getVariation1());
        } else {
            criteria.andIsNull("variation1");
        }

        if (StringUtils.isNotBlank(bomCondition.getVariation2())) {
            criteria.andEqualTo("variation2", bomCondition.getVariation2());
        } else {
            criteria.andIsNull("variation2");
        }

        if (BooleanUtils.isTrue(bomCondition.getIslastiterated())) {
            criteria.andEqualTo("islastiterated", 1);
        }

        return this.typlmPartMapper.selectByExample(ex);
    }

    public List<TyPartAllVO> getSpareBomList(BomCondition bomCondition) {
        return this.typlmPartMapper.getSpareBomList(bomCondition);
    }

    public List<PartDO> queryPartDOByCondition(List<BomCondition> bomConditions) {
        return (List)(ObjectUtils.isEmpty(bomConditions) ? new ArrayList() : this.typlmPartMapper.queryPartDOByCondition(bomConditions));
    }

    public List<TyPartAllVO> queryPartVOByCondition(List<BomCondition> bomConditions) {
        return (List)(ObjectUtils.isEmpty(bomConditions) ? new ArrayList() : this.typlmPartMapper.queryPartVOByCondition(bomConditions));
    }

    public List<PartDO> queryBranchInfoBymasterOidList(List<BigInteger> masterOidList) {
        return (List)(CollUtil.isEmpty(masterOidList) ? new ArrayList() : BatchQueryHelper.batchSplitQuery(masterOidList, (oids) -> {
            return this.typlmPartMapper.queryBranchInfoBymasterOidList(new ArrayList(oids));
        }));
    }

    public List<TyPartAllVO> checkLastedByPartIdList(List<BigInteger> partIdList) {
        return (List)(CollUtil.isEmpty(partIdList) ? new ArrayList() : BatchQueryHelper.batchSplitQuery(partIdList, (oids) -> {
            return this.typlmPartMapper.checkLastedByPartIdList(new ArrayList(oids));
        }));
    }

    public List<PartDO> queryPartByBomConditionNew(BomCondition bomCondition) {
        List<PartDO> result = new ArrayList();
        if (Objects.isNull(bomCondition)) {
            return result;
        } else {
            if (bomCondition.getMasteredoid() != null) {
                bomCondition.getMasteredOids().add(bomCondition.getMasteredoid());
            }

            if (CollUtil.isNotEmpty(bomCondition.getMasteredOids())) {
                List<List<BigInteger>> split = CollUtil.split(CollUtil.distinct(bomCondition.getMasteredOids()), 500);
                Iterator var4 = split.iterator();

                while(var4.hasNext()) {
                    List<BigInteger> list = (List)var4.next();
                    BomCondition condition = new BomCondition();
                    condition.setIsExactQuery(bomCondition.getIsExactQuery());
                    condition.setMasteredoid(bomCondition.getMasteredoid());
                    condition.setViewdefoid(bomCondition.getViewdefoid());
                    condition.setVariation1(bomCondition.getVariation1());
                    condition.setVariation2(bomCondition.getVariation2());
                    condition.setName(bomCondition.getName());
                    condition.setViewName(bomCondition.getViewName());
                    condition.setIslastiterated(bomCondition.getIslastiterated());
                    condition.setOid(bomCondition.getOid());
                    condition.setObjectNumber(bomCondition.getObjectNumber());
                    condition.setUserOid(bomCondition.getUserOid());
                    condition.setMasteredOids(bomCondition.getMasteredOids());
                    condition.setMasteredOids(list);
                    result.addAll(this.typlmPartMapper.queryPartDOByBomCondition(condition));
                }
            } else {
                result.addAll(this.typlmPartMapper.queryPartDOByBomCondition(bomCondition));
            }

            return result;
        }
    }

    public List<PartDO> batchQuerySameBranchPartByIds(List<BigInteger> partIdList) {
        return CollUtil.isEmpty(partIdList) ? Collections.emptyList() : BatchQueryHelper.batchSplitQuery(CollUtil.distinct(partIdList), (oids) -> {
            return this.typlmPartMapper.batchQuerySameBranchPartByIds(new ArrayList(oids));
        });
    }

    public List<PartDO> batchQuerySameViewFactoryPartByIds(List<BigInteger> partIdList) {
        return CollUtil.isEmpty(partIdList) ? Collections.emptyList() : BatchQueryHelper.batchSplitQuery(CollUtil.distinct(partIdList), (oids) -> {
            return this.typlmPartMapper.batchQuerySameViewFactoryPartByIds(new ArrayList(oids));
        });
    }
}
